home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / netlangc.arc / NETLANG.C
Encoding:
C/C++ Source or Header  |  1985-09-05  |  159.4 KB  |  4,187 lines

  1. Article 4303 (653 more) in net.lang.c:
  2. From: teach0@whuts.UUCP (CTD_STUDENT0.)
  3. Subject: Re: Structure question (problem)
  4. Message-ID: <123@whuts.UUCP>
  5. Date: 23 May 85 12:59:40 GMT
  6. Date-Received: 26 May 85 07:14:55 GMT
  7. References: <185@vger.UUCP>
  8. Organization: AT&T Bell Laboratories
  9. Lines: 44
  10.  
  11. --MORE--(34%)
  12. > Could someone please inform me what the hell I am doing wrong.  The
  13. > subject is auto-initialization of structures.  Here is a simple program
  14. > that trys to initialize the stucture, and the associated error
  15. > message.  If I take one of K&R's examples (pg 124, last half page),
  16. > I get the same error.
  17. > BTW-This is 4.2bsd.
  18. > =====
  19. > /* Structure test */
  20. > #include <stdio.h>
  21. > main() {
  22. >       static char *text[] = { "Fred", "Wilma", "Barney", "Betty" };
  23. >       struct l {
  24. >               int a;
  25. >               int b;
  26. >               char *c;
  27. >               int d; 
  28. >                } e = { 0, 1, text[0], 4 };
  29. >       
  30. >       printf("Fred is married to Wilma, Barney to Betty...\n");
  31. > }
  32. > =====
  33. > % cc t.c
  34. > "t.c", line 14: no automatic aggregate initialization
  35. > "t.c", line 14: warning: illegal combination of pointer and integer, op =
  36. Aggregates (arrays, structures, unions) can only be initialized if
  37. they are declared static or external. A simple:
  38.  
  39.         static struct l{ .........
  40.  
  41. will do.
  42.  
  43. --
  44.  
  45. Fred Eng
  46. AT&T Bell Laboratories
  47. (Mail) End of article 4303 (of 4956)--what next? [npq] 
  48.  
  49. Article 4436 (520 more) in net.lang.c:
  50. From: chongo@nsc.UUCP (Landon Noll)
  51. Subject: Re: 2nd Annual Obfuscated Contest Winners
  52. Message-ID: <2919@nsc.UUCP>
  53. Date: 29 Jun 85 04:53:13 GMT
  54. Date-Received: 4 Jul 85 05:49:40 GMT
  55. References: <2902@nsc.UUCP> <36@bbnccv.UUCP>
  56. Reply-To: chongo@nsc.UUCP (Landon Noll)
  57. Distribution: net
  58. Organization: Rational Swamiconductor, Sanivale
  59. Lines: 29
  60. Keywords: precedence
  61. Summary: 
  62.  
  63. --MORE--(31%)
  64. In article <36@bbnccv.UUCP> keesan@bbnccv.UUCP (Morris M. Keesan) writes:
  65.  >1. The most obscure program:
  66.  >(submitted by Lennart Augustsson <seismo!mcvax!enea!chalmers!augustss> )
  67.  >
  68.  >is not legal C, even though the 4.2BSD compiler (and presumably other PCC-based
  69.  >compilers) processes it as the author apparently intended.
  70.  >
  71.  >For these two reasons, especially the first, I don't think this program
  72.  >deserves a prize.  Also, this is a bug in the 4.2BSD compiler, and even more
  73.  >so in the 4.2BSD lint, which should issue a warning even if the compiler is
  74.  >being forgiving.
  75.  
  76. So it breaks on other compilers eh?  Well such is life with a Obfuscated C
  77. contest!  One has to hand it to someone for finding a "hole" in a compiler,
  78. and driving a truck through it. 
  79.  
  80. The contest rules stated that it has to be in "Common C".  There was nothing
  81. to point out that it HAD to be standard C, K&R C, or Deathstar Unix C.
  82. The ability to run an entry on other systems was a plus, not a rule.  Also,
  83. we did not try, nor did we intend to check out each program on every
  84. system/compiler.  We did not have time, or resources to do so!
  85.  
  86. Thank you for posting a suggested change so that other people might see
  87. what the program does.   If anyone else finds another porting problem,
  88. you might consider posting a bug fix to net.sources.bugs.
  89.  
  90. chongo <in any event, the awards are final> /\../\
  91. -- 
  92. no comment is a comment.
  93. (Mail) End of article 4436 (of 4956)--what next? [npq] 
  94.  
  95. Article 4718 (238 more) in net.lang.c:
  96. From: cdshaw@watmum.UUCP (Chris Shaw)
  97. Subject: Re: "writing code"
  98. Message-ID: <227@watmum.UUCP>
  99. Date: 26 Jul 85 07:23:08 GMT
  100. Date-Received: 3 Aug 85 17:22:00 GMT
  101. References: <418@spar.UUCP> <408@utastro.UUCP>
  102. Reply-To: cdshaw@watmum.UUCP (Chris Shaw)
  103. Organization: U of Waterloo, Ontario
  104. Lines: 36
  105.  
  106. --MORE--(28%)
  107. >General question: does anybody "write code" on paper first any more?
  108. >-- 
  109. >Ed Nather
  110.  
  111.  
  112. For me, there is a choice: write it twice (on paper then on screen),
  113. or write it once (on screen only).
  114.  
  115. However, it isn't as hard-and-fast as that. This only truly works for 
  116. simple stuff. For hard programs, I use paper for "getting the algorithm 
  117. into my head". Recently, for example, I had to do a complicated data structure
  118. conversion. The result was terrifically simple, but the core of the
  119. thing was a...
  120.                 x[ --b[ x[ --b[i] ] ] ] = i ;
  121.  
  122. ..kind of affair, which required a lot of thought, and had to be designed
  123. with pictures of linked data structures, etc. etc.
  124.  
  125. The point of all this is that the tools called "paper & pencil" are 
  126. inadequate for designing programs at the textual level, because line 
  127. insertion is improbable, and looks like hell if you do more than a little.
  128.  
  129. Drawing pictures with pencil is easy, though, and impossible on your
  130. normal terminal. If I had access to a good graphics package, one with real
  131. flexibility & "definable actions", then I'd drop paper altogether for design.
  132.  
  133. The conclusion is that this is really an ergonomics issue (if I take the
  134. meaning correctly). Tools that are completely satisfactory/comfortable 
  135. will displace those that aren't.
  136.  
  137.  
  138. Chris Shaw    watmath!watmum!cdshaw  or  cdshaw@watmath
  139. University of Waterloo
  140.  
  141. Work is the curse of the drinking classes.
  142.                 - Oscar Wilde
  143. (Mail) End of article 4718 (of 4956)--what next? [npq] 
  144.  
  145. Article 4719 (237 more) in net.lang.c:
  146. From: guy@sun.uucp (Guy Harris)
  147. Subject: Re: c programming style - READ THIS
  148. Message-ID: <2491@sun.uucp>
  149. Date: 26 Jul 85 07:35:37 GMT
  150. Date-Received: 3 Aug 85 17:32:55 GMT
  151. References: <11570@brl-tgr.ARPA> <935@teddy.UUCP> <1286@uwmacc.UUCP> <2439@sun.uucp> <39@escher.UUCP>
  152. Organization: Sun Microsystems, Inc.
  153. Lines: 47
  154.  
  155. --MORE--(19%)
  156. > I use C largely because it DOES allow (encourage?) me to
  157. > think in terms of the underlying bit patterns involved.  I
  158. > pay very close attention to just what is happening to
  159. > pointers when they are changed; that is the price I pay for
  160. > fast running programs.
  161.  
  162. But is this a case of "thinking of the underlying bit patterns", or is it a
  163. case of thinking of the underlying operations on an abstract machine?  I.e.,
  164. do you think of a pointer as a natural number indexing a large array which
  165. is your process' address space (which may not work on a segmented machine!),
  166. or do you think of it as something that points to an object?  You can still
  167. think in the latter terms without forgetting the important part of how
  168. pointers are implemented - i.e., I doubt the ability to cast pointers to
  169. some integral type and back again is needed, in general, for efficiency
  170.  
  171. > When I AM concerned with performance, I have to put in the
  172. > effort to track every pointer on my own, and all the other
  173. > neat stuff C lets me do without PASCAL or ForTran style
  174. > run-time checking.
  175.  
  176. What do you mean by "track every pointer on (your) own"?  True, you can't
  177. use pointers in FORTRAN without run-time checking, but then you can't use
  178. pointers in FORTRAN *with* run-time checking, since it doesn't *have*
  179. pointers.  FORTRAN doesn't do much "run-time checking" because it doesn't
  180. have much checking to do - no pointers, so no null-pointer checking; no
  181. subrange or enumerated types, so no checking assignments to such types.  I
  182. believe there are many PASCAL compilers that will allow you to turn the
  183. checking off - of course, if you do so, you should have good reason to be
  184. sure the errors that the checking would detect should occur, considering
  185. that those errors can bomb your program regardless of whether it was written
  186. in PASCAL or C.  (For instance, if you get a pointer from a routine which
  187. could return a null pointer, *always* check it before using it unless you
  188. *know* that the particular call to that routine which returns the pointer
  189. won't return a null pointer.  And make *sure* you really "know" it.  Just
  190. because you created a file "/tmp/foo" and made it readable doesn't mean
  191. 'fopen("/tmp/foo", "r")' is not going to return NULL - you could get an I/O
  192. error, or somebody else could have unlinked the file while you weren't
  193. looking, or...)
  194.  
  195.  
  196. You don't have to think of pointers as integers indexing a large array which
  197. is your address space (and think of null pointers as being the integer 0) in
  198. order to write efficient C code.  (And if you do think that way, what you
  199. may end up with is C code that will break when somebody else tries to run it
  200. on their machine - which will force *them* to fix the problem.)
  201.  
  202.         Guy Harris
  203. (Mail) End of article 4719 (of 4956)--what next? [npq] 
  204.  
  205. Article 4720 (236 more) in net.lang.c:
  206. From: agt@pucc-k (Kevin Braunsdorf)
  207. Subject: Inconsistency in Style -> Unreadable Code
  208. Message-ID: <1207@pucc-k>
  209. Date: 26 Jul 85 21:26:56 GMT
  210. Date-Received: 3 Aug 85 17:34:10 GMT
  211. References: work at PUCC
  212. Organization: Solon Aquilla's Magic & Art Gallery
  213. Lines: 35
  214.  
  215. --MORE--(42%)
  216.  
  217.     All: I am a Computing Center Consultant at Purdue so I see more
  218. different styles of coding per week than most programmers do in a year:
  219. in my view the only bad style is an inconsistent one, eg:
  220.  
  221.         kp = ++i * j;
  222.         j += 1;
  223.  
  224.         should be any of:
  225.         i++;                    i += 1;         kp = ++i * j++;
  226.         kp = i * j;             kp = i * j;
  227.         j++;                    j += 1;
  228.  
  229.         or even:
  230.         kp = (i += 1) * j;
  231.         j += 1;
  232.  
  233.     Anything that I can notice a set pattern to will help me read the code:
  234. as to the formatting of the code, I personally use
  235.         while (exp) {
  236.             ...
  237.         }       /* line close curly with while  */
  238.     but
  239.         while (exp) {
  240.             ...
  241.             }   /* indent curly too             */
  242.     works for me too, as long as
  243.         fnx()
  244.             {
  245.             ...
  246.             }
  247.     is used too!
  248.  
  249.                                                 :wq
  250.                                                 Kevin Braunsdorf
  251. (Mail) End of article 4720 (of 4956)--what next? [npq] 
  252.  
  253. Article 4721 (235 more) in net.lang.c:
  254. From: chuqui@nsc.UUCP (Chuq Von Rospach)
  255. Subject: Re: C Programming Style -- New thought  ("writing code")
  256. Message-ID: <3035@nsc.UUCP>
  257. Date: 27 Jul 85 04:07:36 GMT
  258. Date-Received: 4 Aug 85 00:57:45 GMT
  259. References: <418@spar.UUCP> <408@utastro.UUCP> <107@well.UUCP>
  260. Reply-To: chuqui@nsc.UUCP (Chuq Von Rospach)
  261. Organization: The Dreamer Fithp
  262. Lines: 13
  263. Summary: 
  264.  
  265. --MORE--(49%)
  266. In article <408@utastro.UUCP>, nather@utastro.UUCP (Ed Nather) writes:
  267. > General question: does anybody "write code" on paper first any more?
  268.  
  269. I use paper for any non-trivial design, and usually find myself going
  270. through three or four circuits fleshing it from something resembling
  271. pseudo-code to something resembling C. Even better, when I'm actually in my
  272. office, is my white board -- I don't know how people lived without them.
  273. -- 
  274. :From the carousel of the autumn carnival:        Chuq Von Rospach
  275. {cbosgd,fortune,hplabs,ihnp4,seismo}!nsc!chuqui   nsc!chuqui@decwrl.ARPA
  276.  
  277. Your fifteen minutes are up. Please step aside!
  278. (Mail) End of article 4721 (of 4956)--what next? [npq] 
  279.  
  280. Article 4723 (233 more) in net.lang.c:
  281. From: mauney@ncsu.UUCP (Jon Mauney)
  282. Subject: Re: Style, readability, etc. (use of comments)
  283. Message-ID: <2904@ncsu.UUCP>
  284. Date: 26 Jul 85 15:11:17 GMT
  285. Date-Received: 4 Aug 85 01:13:50 GMT
  286. References: <95@brl-tgr.ARPA>, <1207@sjuvax.UUCP>
  287. Organization: N.C. State University, Raleigh
  288. Lines: 39
  289.  
  290. --MORE--(22%)
  291. > From: jss@sjuvax.UUCP (J. Shapiro)
  292. > Subject: Re: Style, readability, etc. (long, but IMPORTANT)
  293. > Message-ID: <1207@sjuvax.UUCP>
  294. >   
  295. > > while(ptr++->duck)  /* move pointer to the duck after the next NULL */
  296. > >   ;
  297. > This one is even more obscure than the last.  I am a C programmer, and
  298. > this tells me nothing - indeed it is dead wrong, as it simply will not
  299. > happen as the comment might lead me to believe.  This will leave me
  300. > with ptr pointing to the next available record whose element named
  301. > duck is 0.  It certainly has nothing to do with NULL or anything after
  302. > duck.  This is one of the major difficulties with such comments.
  303. > There is a tendency even among experienced programmers to read them
  304. > and believe them, and thereby not see an obvious difficulty.
  305. > Jonathan S. Shapiro
  306. > Haverford College
  307. > ..!sjuvax!jss
  308.  
  309. Let me first point out that I agree that block comments are generally
  310. more useful than end-of-line comments.  However, there are many places
  311. in which an end-of-line comment is very useful.  The present example
  312. is one, as proved by the fact that apparently experienced C programmers
  313. cannot agree on the effect of the loop.  Code that is so susceptible to
  314. error should be avoided or heavily commented.
  315.  
  316. I look at comments as recording the programmer's *intent*, whereas the
  317. code is (obviously) what he actually *did*.  Reading the comments tells
  318. me whether the bug is likely due to a poor design.  If the design
  319. seems sound, then I look for discrepancies between code and comments.
  320. Any such discrepancy is a clear indication of a problem, although the
  321. problem may be as simple as a slip of the mind.  Comments add redundancy
  322. to a program, and redundancy is A Good Thing, in moderation.
  323. -- 
  324.  
  325. Jon Mauney,    mcnc!ncsu!mauney       "The door's not shut on my genius, but...
  326. North Carolina State University        I just don't have the time."
  327. (Mail) End of article 4723 (of 4956)--what next? [npq] 
  328.  
  329. Article 4724 (232 more) in net.lang.c:
  330. From: chris@umcp-cs.UUCP (Chris Torek)
  331. Subject: Re:  C Programming Style -- New thought (\"writing code\")
  332. Message-ID: <1017@umcp-cs.UUCP>
  333. Date: 26 Jul 85 21:31:08 GMT
  334. Date-Received: 4 Aug 85 02:23:43 GMT
  335. References: <189@brl-tgr.ARPA>
  336. Organization: U of Maryland, Computer Science Dept., College Park, MD
  337. Lines: 18
  338.  
  339. --MORE--(47%)
  340. >Typing ability probably has a lot to do with [programming on paper]
  341. >to [sic].
  342.  
  343. Could be; I never write actual code on paper, and I type MUCH faster
  344. than I write (I type reasonably quickly and write excruciatingly
  345. slowly)....
  346.  
  347. However, I don't think that writing code on paper gains you much
  348. if anything.  The key to writing good code is to have a clear
  349. understanding of the algorithm(s) involved.
  350.  
  351. In some cases I need to do a complete rewrite after I've got
  352. something working, once I know what I did wrong the first time
  353. around....
  354. -- 
  355. In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 4251)
  356. UUCP:   seismo!umcp-cs!chris
  357. CSNet:  chris@umcp-cs           ARPA:   chris@maryland
  358. (Mail) End of article 4724 (of 4956)--what next? [npq] 
  359.  
  360. Article 4725 (231 more) in net.lang.c:
  361. From: ado@elsie.UUCP (Arthur David Olson)
  362. Newsgroups: net.unix,net.lang.c
  363. Subject: Re: Portablity using structures and malloc - Help
  364. Message-ID: <5181@elsie.UUCP>
  365. Date: 27 Jul 85 00:36:19 GMT
  366. Date-Received: 4 Aug 85 02:25:51 GMT
  367. References: <81@drux1.UUCP> <907@umcp-cs.UUCP> <4772@allegra.UUCP> <257@bocklin.UUCP>
  368. Organization: NIH-LEC, Bethesda, MD
  369. Lines: 13
  370. Summary: bit field vs. char
  371.  
  372. --MORE--(55%)
  373. In article <257@bocklin.UUCP>, wendt@bocklin.UUCP writes:
  374. > An easy way to determine alignment requirements is to take the size
  375. > of a structure containing one character.  Odd-length structures are
  376. > invariably rounded up to convenient units by the compiler.
  377.  
  378. Or, preferably,
  379.         #define ALIGNMENT (sizeof (struct { char :1;}))
  380. which avoids having to make up a name for a structure element.
  381. --
  382. UNIX is an AT&T Bell Laboratories trademark.
  383. --
  384.         UUCP: ..decvax!seismo!elsie!ado    ARPA: elsie!ado@seismo.ARPA
  385.         DEC, VAX and Elsie are Digital Equipment and Borden trademarks
  386. (Mail) End of article 4725 (of 4956)--what next? [npq] 
  387.  
  388. Article 4726 (230 more) in net.lang.c:
  389. From: edg@well.UUCP (Ed Greenberg)
  390. Subject: Re: C Programming Style -- New thought  ("writing code")
  391. Message-ID: <107@well.UUCP>
  392. Date: 26 Jul 85 16:16:55 GMT
  393. Date-Received: 4 Aug 85 03:17:03 GMT
  394. References: <418@spar.UUCP> <408@utastro.UUCP>
  395. Organization: Whole Earth 'Lectronic Link, Sausalito, CA
  396. Lines: 15
  397. Summary: composing code on paper
  398.  
  399. --MORE--(60%)
  400. In article <408@utastro.UUCP>, nather@utastro.UUCP (Ed Nather) writes:
  401. > General question: does anybody "write code" on paper first any more?
  402. > -- 
  403.  
  404. I start to write functions on paper, but you can't use insert
  405. functions on paper!  When I start to stick things in above, I
  406. usually go to the terminal.
  407.  
  408. I DO write pseudocode on paper though.  Sometimes on index
  409. cards.
  410.  
  411.                         -edg
  412.  
  413. {hplabs,dual,ptsfa}!well!micropro!edg
  414. (Mail) End of article 4726 (of 4956)--what next? [npq] 
  415.  
  416. Article 4843 (113 more) in net.lang.c:
  417. From: ark@alice.UUCP (Andrew Koenig)
  418. Subject: Re: how has C bitten you?
  419. Message-ID: <4170@alice.UUCP>
  420. Date: 18 Aug 85 15:07:03 GMT
  421. Date-Received: 24 Aug 85 05:29:41 GMT
  422. References: <228@investor.UUCP>
  423. Organization: Bell Labs, Murray Hill
  424. Lines: 17
  425.  
  426. --MORE--(55%)
  427. > int dial(telno)
  428. > char *telno;
  429. > {
  430. >       if(telno){              /*  should be if(*telno)  */
  431. >               dial it;
  432. >       }
  433. >       else{
  434. >               hang up;
  435. >       }
  436. > }
  437.  
  438. Bob Pierce says that this program failed because it should have been
  439. checking *telno instead of telno.
  440.  
  441. If telno is NULL, you had better not look at *telno; it's illegal.
  442. If the address of a legal character item is NULL, your compiler is
  443. not implementing the language properly.
  444. (Mail) End of article 4843 (of 4956)--what next? [npq] 
  445.  
  446. Article 4844 (112 more) in net.lang.c:
  447. From: guy@sun.uucp (Guy Harris)
  448. Subject: Re: What is wrong with this program?
  449. Message-ID: <2654@sun.uucp>
  450. Date: 17 Aug 85 03:43:02 GMT
  451. Date-Received: 24 Aug 85 06:17:17 GMT
  452. References: <117@graffiti.UUCP> <353@ttrdc.UUCP> <9940@ucbvax.ARPA>
  453. Distribution: net
  454. Organization: Sun Microsystems, Inc.
  455. Lines: 14
  456.  
  457. --MORE--(55%)
  458. >       Not really, you are forgetting that the format "%.8s" will
  459. > cause printf to print up to a null or 8 chars max.  Unfortunately
  460. > this style of printf can not be used with sizeof for compile time
  461. > format changes without run time code support.
  462.  
  463. True, you can't have the compiler generate the "printf" string, but you can
  464. do
  465.  
  466.         printf("%.*s", sizeof(thing), thing);
  467.  
  468. since you can use "*" for a field width or precision and pick up the value
  469. from the argument list.
  470.  
  471.         Guy Harris
  472. (Mail) End of article 4844 (of 4956)--what next? [npq] 
  473.  
  474. Article 4845 (111 more) in net.lang.c:
  475. From: klong@datlog.UUCP ( Kevin Long )
  476. Newsgroups: net.bugs.usg,net.lang.c
  477. Subject: Possible bug in VAX 11/750 C compiler
  478. Message-ID: <261@datlog.UUCP>
  479. Date: 14 Aug 85 16:20:45 GMT
  480. Date-Received: 24 Aug 85 07:30:38 GMT
  481. Organization: Data Logic Ltd, Greenford, London.
  482. Lines: 51
  483. Xpath: stc stc-a
  484.  
  485. --MORE--(32%)
  486.  
  487.     Our company is running system 5.2 on a VAX 11/750 and we have a problem with    our compiler in the area of compile time evaluation of constants.
  488.     The problem has appeared after using the system include file values.h to
  489.     define the value MAXSHORT, the maximum value a short can hold.
  490.     This is defined as follows.
  491.  
  492. #define BITSPERBYTE     8
  493. #define BITS(type)      (BITSPERBYTE * (int)sizeof(type))
  494. #define HIBITS          ((short)(1 << BITS(short) - 1))
  495. #define MAXSHORT        ((short)~HIBITS)
  496.  
  497.     After cpp has finished with MAXSHORT it looks like
  498.  
  499. ((short)~((short)(1 << (8 * (int)sizeof(short)) - 1)))
  500.  
  501.     and the compiler treats this at compile time as -32769; (of some size).
  502.     If we now define 
  503.  
  504. int a = 1;
  505.  
  506.     Then neither of the following code works as expected
  507.  
  508. if ( (short) a < MAXSHORT) ....;
  509.  
  510. if ( a < (int) MAXSHORT) ....;
  511.  
  512.     The problem is created by the compiler evaluating constants as longs, signed    unless explicitly told to do otherwise, so the problem goes away if short is    changed to unsigned short in the definitions of MAXSHORT and HIBITS above;
  513.  
  514.     Is this a bug in the compiler or a bad definition in values.h ??
  515. -- 
  516.  
  517.  
  518.                                 Klong
  519.  
  520. The views expressed above are not those of my employer but those of my pet Panda
  521. UUCP: ...!mcvax!ukc!stc!datlog!klong
  522. MAIL: Data Logic Ltd., 320, Ruislip Road East, Greenford, Middlesex, UK.
  523. (Mail) End of article 4845 (of 4956)--what next? [npq] 
  524.  
  525. Article 4846 (110 more) in net.lang.c:
  526. From: lam@btnix.UUCP (lam)
  527. Subject: Re: how has C bitten you? (and a sidetrack)
  528. Message-ID: <16@btnix.UUCP>
  529. Date: 23 Aug 85 10:48:29 GMT
  530. Date-Received: 24 Aug 85 07:31:02 GMT
  531. References: <4051@alice.UUCP> <2600011@ccvaxa>
  532. Organization: British Telecom, Ipswich, England
  533. Lines: 34
  534. Xpath: icdoc ivax
  535.  
  536. --MORE--(32%)
  537. [*** The Phantom Article Gobbler Strikes Again ***]
  538. > > >   int i, a[10];
  539. > > >   for (i = 0; i <= 10; i++)
  540. > > >           a[i] = 0;
  541. > > > 
  542.  
  543. > > This looks to me like it will simply overwrite one int's worth of
  544. > > memory beyond the end of the array "a" with the value 0.  Granted,
  545. > > depending on what happens to be after "a", this can have disastrous
  546. > > results, but is there really an implementation in which it will
  547. > > (reliably) lead to infinte looping?
  548. > ----------
  549. > Yes.  Any implementation that allocates the space for i following the
  550. > space for a.
  551.  
  552. The cause of the infinite loop is due to the storage allocation.
  553.         i.e.    &i == &a[10]
  554.    causing i to be overwritten with 0 when i is 10.
  555.  
  556. The more interesting thing is that on some compilers, the infinite
  557.    loop does NOT occur.  Lo and behold, the OPTIMISER comes into play.
  558.    If i is put in a Register at the start of the for(), a[10] = 0 
  559.    will indeed overwrite i in memory but not the register !!! and the
  560.    loop terminates normally.
  561.    What's worse, the optimiser has in this case hidden a program bug!!!
  562.  
  563. Thus the moral:
  564.  
  565.         "Don't just test your code once.  Test it again, this time
  566.          turn the optimiser OFF first".
  567.  
  568. ------------------------------------------------------------------
  569.         Onward Lam 
  570.         CAP Group, Reading, England.
  571. (Mail) End of article 4846 (of 4956)--what next? [npq] 
  572.  
  573. Article 4847 (109 more) in net.lang.c:
  574. From: rbp@investor.UUCP (Bob Peirce)
  575. Subject: Re: how has C bitten you?
  576. Message-ID: <228@investor.UUCP>
  577. Date: 15 Aug 85 23:24:51 GMT
  578. Date-Received: 24 Aug 85 07:31:23 GMT
  579. Organization: Cookson, Peirce & Co., Pittsburgh, PA
  580. Lines: 26
  581.  
  582. --MORE--(48%)
  583. Here's one that trapped me this week.  It took much head scratching
  584. and debug prints to figure it out.
  585.  
  586. int dial(telno)
  587. char *telno;
  588. {
  589.         if(telno){              /*  should be if(*telno)  */
  590.                 dial it;
  591.         }
  592.         else{
  593.                 hang up;
  594.         }
  595. }
  596.  
  597. Print statements showed the telno was being handed to the routine,
  598. but the if said nothing was there.  Turns out, on my system, the
  599. address of telno is NULL.  I needed to check the contents not the
  600. address!
  601. -- 
  602.  
  603.                         Bob Peirce, Pittsburgh, PA
  604.                 uucp: ...!{allegra, bellcore, cadre, idis}
  605.                          !pitt!darth!investor!rbp
  606.                                 412-471-5320
  607.  
  608.                 NOTE:  Mail must be < 30,000 bytes/message
  609. (Mail) End of article 4847 (of 4956)--what next? [npq] 
  610.  
  611. Article 4848 (108 more) in net.lang.c:
  612. From: daveb@rtech.UUCP (Dave Brower)
  613. Subject: C Idioms - reference work?
  614. Message-ID: <597@rtech.UUCP>
  615. Date: 16 Aug 85 08:00:52 GMT
  616. Date-Received: 24 Aug 85 07:32:57 GMT
  617. References: <359@tektools.UUCP> <30000008@ISM780.UUCP>
  618. Organization: Relational Technology, Alameda CA
  619. Lines: 11
  620.  
  621. --MORE--(59%)
  622. I recall hearing a rumour a year or two ago about a hardcopy reference
  623. to many common 'C' idioms.  It may have come out of some European
  624. University.  Has anyone heard of such a beast, and know where I might
  625. obtain a copy?
  626.  
  627. -dB
  628.  
  629. -- 
  630. {amdahl|dual|sun|zehntel}\              |"If his brains ran down, how could
  631. {ucbvax|decvax}!mtxinu---->!rtech!daveb |he talk?"
  632. ihnp4!{phoenix|amdahl}___/              |"Happens to people all the time...."
  633. (Mail) End of article 4848 (of 4956)--what next? [npq] 
  634.  
  635. Article 4849 (107 more) in net.lang.c:
  636. From: levy@ttrdc.UUCP (Daniel R. Levy)
  637. Subject: Re: how has C bitten you?  (Really, style)
  638. Message-ID: <372@ttrdc.UUCP>
  639. Date: 19 Aug 85 16:41:52 GMT
  640. Date-Received: 24 Aug 85 09:45:17 GMT
  641. References: <302@brl-tgr.ARPA> <4081@alice.UUCP> <243@ecrhub.UUCP> <123@ecsvax.UUCP> <389@phri.UUCP>
  642. Distribution: net
  643. Organization: AT&T, Computer Systems Division, Skokie, IL
  644. Lines: 30
  645.  
  646. --MORE--(33%)
  647. In article <389@phri.UUCP>, roy@phri.UUCP (Roy Smith) writes:
  648. >       Here's one that just got me:
  649. >
  650. >               if (sv > score);   <----- note extraneous semi-colon
  651. >                       score = sv;
  652. >
  653. >       This was in a series of computations which gave various scores; the
  654. >fragment above was repeated in various places to pick out the maximum.  Of
  655. >course, the test is a no-op and the assignment was always done.  Naturally,
  656. >this passes lint (even with the -h flag which uses "heuristic tests to
  657. >attempt to intuit bugs") without any complaint.
  658. >--
  659. >Roy Smith <allegra!phri!roy>
  660.  
  661. Sounds like a question of style hiding function.  Why not stick to something
  662. like
  663.  
  664.                 if (sv > score) score = sv;
  665.  
  666. ?
  667.  
  668. I can't think of anything much more straightforward than that.
  669. -- 
  670.  -------------------------------    Disclaimer:  The views contained herein are
  671. |       dan levy | yvel nad      |  my own and are not at all those of my em-
  672. |         an engihacker @        |  ployer, my pets, my plants, my boss, or the
  673. | at&t computer systems division |  s.a. of any computer upon which I may hack.
  674. |        skokie, illinois        |
  675. |          "go for it"           |  Path: ..!ihnp4!ttrdc!levy
  676.  --------------------------------     or: ..!ihnp4!iheds!ttbcad!levy
  677. (Mail) End of article 4849 (of 4956)--what next? [npq] 
  678.  
  679. Article 4851 (105 more) in net.lang.c:
  680. From: stern@bnl.UUCP (eric)
  681. Subject: Re: VAX VMS C / UNIX C Compatibility --
  682. Message-ID: <142@bnl.UUCP>
  683. Date: 17 Aug 85 06:17:25 GMT
  684. Date-Received: 26 Aug 85 02:56:32 GMT
  685. References: <488@rdin.UUCP> <3400003@ndm20>
  686. Organization: Brookhaven National Lab. Upton, N.Y.
  687. Lines: 70
  688.  
  689. --MORE--(13%)
  690. > >Another thing I'm looking for under VMS is the ability to load both
  691. > >C and FORTRAN object files into one executable. Does anyone know if
  692. > >this works?
  693. > It is supposed to but some while ago, there was a discussion on 
  694. > INFO-VAX saying that C in some way violated the VMS procedure calling
  695. > standard. Thus there is one or more obscure case that fails. This
  696. > is ironic in that the calling standard is highly touted by DEC. This 
  697. > discussion predated VMS4, so they may have fixed it.
  698.  
  699. I don't know if I would make too much of this.  The procedure calling
  700. calling standard is only that and nothing more.  The fact that I can
  701. violate the standard in C, is just a function of the fact that I can
  702. do most anything in C.  I can violate the standard by doing certain
  703. things in MACRO also, so this is just another example of "I can do
  704. anything in C that I can do in MACRO".  There are rather simple
  705. rules to follow if you are programming in C and are interfacing to
  706. other languages to make a program comply with the procedure calling
  707. standard.  Note that there is no problem if a program is entirely
  708. written in C, so that this problem will not effect the porting
  709. of existing C programs.
  710.  
  711. > There is also a general rule that happens to apply in this case, that
  712. > I/O can only be done from routines in the same language as the main. 
  713. > This is because that is where most compilers on most machines put the
  714. > calls to the I/O system initializers, and few languages share I/O 
  715. > systems. On some machines, you can't even do it if there are routines
  716. > of another language between the main and the routine in question.
  717.  
  718. This may have been the case in an old version of VMS, but it certainly
  719. isn't correct now.  I regularly mix FORTRAN and PASCAL I/O, and I just
  720. verified that I can do C standard I/O mixed with PASCAL I/O.  In VMS
  721. run-time systems, initialized data is linked in the run-time libraries
  722. as initialized copy-on-reference data, and so no initialization needs
  723. to be done at run time.  The biggest problem one is likely to run
  724. into when mixing I/O to the terminal is that FORTRAN, PASCAL, and C
  725. all have different ideas about carriage control, and each maintains
  726. a separate picture of what carriage control characters are necessary.
  727.  
  728. > Terry Poot
  729. > Nathan D. Maier Consulting Engineers
  730. > (214)739-4741
  731. > Usenet: ...!{allegra|ihnp4}!convex!smu!ndm20!tp
  732. > CSNET:  ndm20!tp@smu
  733. > ARPA:   ndm20!tp%smu@csnet-relay.ARPA
  734.  
  735. In general, C programs that do I/O with standard I/O library
  736. interfaces (getc, printf, etc...), use math library functions, and
  737. that don't use things like stat and ioctl can be expected to work
  738. unmodified on VMS systems.  Programs that use (read, write, open, creat)
  739. will work in many cases, although they will have to be looked at
  740. carefully.  In particular, the file formats may cause a problem.
  741. Programs that rely on forking/vforking and pipes will probably
  742. need major changes to run.  DEC supplies an implementation of
  743. vfork and pipes, but it is so limited that I suspect it may not
  744. be useful.  Still, if your program happens to fall within the
  745. limitations, it may run, although with a severe performance problem.
  746. There are many miscellaneous routines supplied for compatabilility with
  747. UNIX, and if a program uses them, there is a large chance it will
  748. work for both UNIX and VMS.  This compatability has expanded a lot
  749. in the last release of the C compiler and I have not had a chance
  750. to fully explore the new stuff.  It looks like there is even a
  751. curses.
  752.  
  753.                                         Eric G. Stern
  754.                                         Dept. of Physics SUNY StonyBrook
  755.                                         stern@bnl.arpa
  756.                                         stern@bnl.bitnet
  757.                                         stern@bnldag.bitnet
  758.                                         ...!philabs!sbcs!bnl!stern
  759. (Mail) End of article 4851 (of 4956)--what next? [npq] 
  760.  
  761. Article 4852 (104 more) in net.lang.c:
  762. From: dimitrov@csd2.UUCP (Isaac Dimitrovsky)
  763. Subject: Bug in lint ?
  764. Message-ID: <3090005@csd2.UUCP>
  765. Date: 20 Aug 85 19:47:00 GMT
  766. Date-Received: 26 Aug 85 03:48:25 GMT
  767. Organization: New York University
  768. Lines: 29
  769.  
  770. --MORE--(39%)
  771. []
  772.  
  773. I've run into a possible bug in lint. It can be reproduced on my system
  774. (VAX 4.2BSD) by running lint -ap on the program below. This produces:
  775.  
  776. try.c:
  777. try.c(5): warning: long assignment may lose accuracy
  778.  
  779. The options a and p are supposed to check for assignments of longs to
  780. ints and incompatibilities with the IBM and GCOS dialects of C,
  781. respectively. Strangely enough, when I just run lint with the a option
  782. or the p option alone, the program goes through with no messages.
  783. Any explanations or ideas welcome.
  784.  
  785. main() {
  786.         long a;
  787.         int i;
  788.  
  789.         a=0; i=1;
  790.         if ((a & (1L<<i)) != 0L)
  791.                 a++;
  792. }
  793.  
  794. Isaac Dimitrovsky
  795. allegra!cmcl2!csd2!dimitrov   (l in cmcl2 is letter l not number 1)
  796. 251 Mercer Street, New York NY 10012
  797.  
  798. ... Hernandez steps in to face ... Orl ... HERchiiiser ... and it's a liiine
  799. driive, deeeeep to the gap in left center ...   - Bob Murphy, Voice of the Mets
  800. (Mail) End of article 4852 (of 4956)--what next? [npq] 
  801.  
  802.  
  803. Article 4854 (102 more) in net.lang.c:
  804. From: freeman@spar.UUCP (Jay Freeman)
  805. Subject: Re: more about programming style
  806. Message-ID: <476@spar.UUCP>
  807. Date: 21 Aug 85 20:39:56 GMT
  808. Date-Received: 26 Aug 85 04:28:15 GMT
  809. References: <11457@brl-tgr.ARPA> <68@ucbcad.UUCP> <1693@reed.UUCP> <441@myriasb.UUCP> <141@rpics.UUCP> <457@lasspvax.UUCP> <1317@eagle.UUCP>21 Aug 85 20:39:56 GMT
  810. Reply-To: freeman@max.UUCP (Jay Freeman)
  811. Organization: Schlumberger Palo Alto Research, CA
  812. Lines: 17
  813.  
  814. --MORE--(48%)
  815. [libation to line-eater]
  816.  
  817. In article <16220@watmath.UUCP> rbutterworth@watmath.UUCP (Ray Butterworth) writes:
  818.  
  819. >Even simpler.  Replace "<=" with "!>", and ">=" with "!<".  This gives
  820. >even more consistency since you can now have "!<", "!>", and "!=".
  821.  
  822. I suspect that Ray Butterworth may have had a :-) in mind when he wrote
  823. these lines, but I kind of _like_ "!<" and "!>".  I guess I always think of
  824. "<=" -- for example -- as two separate tests and have to combine both of
  825. them mentally when I am figuring out what something does.  (Or maybe it's
  826. brain-damage from writing too many lines of assembler.)  Anyway, those might
  827. be a reasonable enhancement, and surely would be all but free in terms of
  828. additional compiler complexity.
  829.  
  830.  
  831. -- 
  832. Jay Reynolds Freeman (Schlumberger Palo Alto Research)(canonical disclaimer)
  833. (Mail) End of article 4854 (of 4956)--what next? [npq] 
  834.  
  835. Article 4855 (101 more) in net.lang.c:
  836. From: robert@cheviot.uucp (Robert Stroud)
  837. Subject: Re: Exception Handling?  Impossible!
  838. Message-ID: <414@cheviot.uucp>
  839. Date: 19 Aug 85 16:40:50 GMT
  840. Date-Received: 26 Aug 85 04:36:28 GMT
  841. References: <10200002@ada-uts.UUCP>
  842. Reply-To: robert@cheviot.UUCP (Robert Stroud)
  843. Organization: U. of Newcastle upon Tyne, U.K.
  844. Lines: 25
  845.  
  846. --MORE--(46%)
  847. Rich Wagner (richw@ada-uts.UUCP) posted some macros for exception handling
  848. and asked for comments and suggestions.
  849.  
  850. I can recommend an article in Software Practice & Experience by Peter Lee
  851. a few years ago (1983, pp 389-405) which describes a series of macros and
  852. routines which add exception handling in the style of Ada or Clu to C.
  853. Basically they work by hiding a stack of setjmp/longjmp contexts inside
  854. a macro skeleton of
  855.  
  856.         BEGIN
  857.            ...
  858.         EXCEPT
  859.            WHEN(exception1) ...
  860.            WHEN(exception2) ...
  861.            OTHERS ...
  862.         END
  863.  
  864. I can post the code from the article if there is enough interest.
  865.  
  866. Robert Stroud,
  867. Computing Laboratory,
  868. University of Newcastle upon Tyne.
  869.  
  870. UUCP ...!ukc!cheviot!robert
  871. ARPA robert%cheviot.newcastle@ucl-cs.ARPA
  872. (Mail) End of article 4855 (of 4956)--what next? [npq] 
  873.  
  874. Article 4856 (100 more) in net.lang.c:
  875. From: rbp@investor.UUCP (Bob Peirce)
  876. Subject: Re: how has C bitten you? (and a sidetrack)
  877. Message-ID: <229@investor.UUCP>
  878. Date: 19 Aug 85 00:00:19 GMT
  879. Date-Received: 26 Aug 85 04:37:09 GMT
  880. References: <4051@alice.UUCP> <2600011@ccvaxa> <16@btnix.UUCP>
  881. Organization: Cookson, Peirce & Co., Pittsburgh, PA
  882. Lines: 16
  883.  
  884. --MORE--(62%)
  885. >    What's worse, the optimiser has in this case hidden a program bug!!!
  886. > Thus the moral:
  887. >       "Don't just test your code once.  Test it again, this time
  888. >        turn the optimiser OFF first".
  889.  
  890. and vice versa!
  891. -- 
  892.  
  893.                         Bob Peirce, Pittsburgh, PA
  894.                 uucp: ...!{allegra, bellcore, cadre, idis}
  895.                          !pitt!darth!investor!rbp
  896.                                 412-471-5320
  897.  
  898.                 NOTE:  Mail must be < 30,000 bytes/message
  899. (Mail) End of article 4856 (of 4956)--what next? [npq] 
  900.  
  901. Article 4857 (99 more) in net.lang.c:
  902. From: guy@sun.uucp (Guy Harris)
  903. Newsgroups: net.lang.c,net.unix
  904. Subject: Re: Not checking printf's result causes another news bug
  905. Message-ID: <2677@sun.uucp>
  906. Date: 20 Aug 85 06:12:30 GMT
  907. Date-Received: 26 Aug 85 04:45:41 GMT
  908. References: <11@brl-tgr.ARPA> <1288@eagle.UUCP> <15908@watmath.UUCP> <116@rtp47.UUCP> <1096@diku.UUCP> <413@brl-Re: Not checking printf's re20 Aug 85 06:12:30 GMT
  909. Followup-To: net.unix
  910. Organization: Sun Microsystems, Inc.
  911. Lines: 36
  912.  
  913. --MORE--(32%)
  914. > You could set up a (in unix lingo) a signal handler and if any I/O error
  915. > occurred it would interrupt to that routine. Now this was on a per-write
  916. > (actually, per I/O) basis but what I have in mind here is to do something
  917. > like:
  918. >
  919. > #define printf eprintf
  920. > #define fprintf efprintf
  921. > then add to main() something like
  922. >       signal(SIGIOT,myhandler) ;      /* choose a signal, SIGIOT seems good*/
  923.  
  924. No, SIGIOT is what "abort()" causes (except on 4.xBSD - in System V it uses
  925. "kill" so that you can get SIGIOT even if you don't have an IOT
  926. instruction).  In S3/S5/4.3BSD, you can use SIGUSR1; in older BSD releases,
  927. #define SIGUSR1 as 30, and in V7 #define it as 16.  This signal (as the name
  928. suggests) is reserved for user program use.
  929.  
  930. In System III and System V, though, there is a "software signal" mechanism -
  931. see SSIGNAL(3C).  The claim is made there that "this facility is used by the
  932. Standard C Library to enable users to indicate the disposition of error
  933. signals", but this claims is false; nowhere in the C library is it used.  I
  934. suspect it was intended for this purpose, but nobody bothered changing the
  935. library to use it.  For those of you with non-S3 or S5 systems who have a
  936. source license, you can drop it in.
  937.  
  938. > and something reasonable for myhandler() and finally:
  939. > eprintf(fmt,a,b,c,d,e,f,g...) /* etc or maybe use varargs */
  940. > {
  941.  
  942. Or, preferably, use "vprintf" and its siblings if you have them.  They come
  943. with S3, and with S5R2, but *not* with S5R1.  They can be easily implemented
  944. in any system with "_doprnt" (S5R2 has it and that's how it implements them).
  945.  
  946.         Guy Harris
  947. (Mail) End of article 4857 (of 4956)--what next? [npq] 
  948.  
  949. Article 4858 (98 more) in net.lang.c:
  950. From: cdshaw@watmum.UUCP (Chris Shaw)
  951. Subject: Re: how has C bitten you?  (Really, style)
  952. Message-ID: <259@watmum.UUCP>
  953. Date: 22 Aug 85 00:41:39 GMT
  954. Date-Received: 26 Aug 85 05:10:44 GMT
  955. References: <302@brl-tgr.ARPA> <4081@alice.UUCP> <243@ecrhub.UUCP> <123@ecsvax.UUCP> <389@phri.UUCP> <372@ttrdc.UUCP>
  956. Reply-To: cdshaw@watmum.UUCP (Chris Shaw)
  957. Distribution: net
  958. Organization: U of Waterloo, Ontario
  959. Lines: 44
  960.  
  961. --MORE--(25%)
  962. In article <372@ttrdc.UUCP> levy@ttrdc.UUCP (Daniel R. Levy) writes:
  963. >In article <389@phri.UUCP>, roy@phri.UUCP (Roy Smith) writes:
  964. >>      Here's one that just got me:
  965. >>              if (sv > score);   <----- note extraneous semi-colon
  966. >>                      score = sv;
  967. >
  968. >Sounds like a question of style hiding function.  Why not stick to something
  969. >like
  970. >               if (sv > score) score = sv;
  971. >?
  972. >|       dan levy 
  973.  
  974. ...because 
  975.  
  976. if(sv>score||this==that+the_other||fopen("crap","r"))save=the+whales+fur+christ++;
  977.  
  978. is the kind of statement where bugs really happen. Can you seriously spend less
  979. than two seconds reading that to comprehend what's going on ? If you answered
  980. yes, how about this (more important) question: Can you read a whole FILE of
  981. this kind of crap and then be able to find a variable at will ?
  982.  
  983. I doubt it. I can think of more straightforward ways of producing code, some
  984. of which include programming while awake, so that the errors like the
  985. one in the original posting don't happen. Others include using a self-consistentstyle, which Mr Levy's is not. Compound if statements should look the same
  986. as simple if statements.
  987.  
  988. Mr Levy's style of if statement has an equivalent in English called 
  989. "the run-on-sentence". What's silly about the whole thing is that a program
  990. formatter can make this stuff QUITE readable, and will probably find the
  991. bug that "bit" Mr Smith.
  992.  
  993. The most important element of a readable programming style is the use of white
  994. space. I personally can't stand the K&R style because I get visually confused
  995. when I read it. It's similar to an English paragraphing that doesn't use
  996. indenting or spaces between paragraphs. In the C book itself, this isn't bad,
  997. because the program fragments are small and the structures are simple.
  998. In real programs, however, there are lots of programs which are unreadable
  999. until passed through "indent" (on 4.2).
  1000.  
  1001.  
  1002. Chris Shaw    watmath!watmum!cdshaw  or  cdshaw@watmath
  1003. University of Waterloo
  1004. In doubt?  Eat hot high-speed death -- the experts' choice in gastric vileness !(Mail) End of article 4858 (of 4956)--what next? [npq] 
  1005.  
  1006. Article 4859 (97 more) in net.lang.c:
  1007. From: cdshaw@watmum.UUCP (Chris Shaw)
  1008. Subject: Re: VAX VMS C / Rash attempt at porting Kermit
  1009. Message-ID: <260@watmum.UUCP>
  1010. Date: 22 Aug 85 01:08:01 GMT
  1011. Date-Received: 26 Aug 85 05:10:55 GMT
  1012. References: <488@rdin.UUCP> <249@watmum.UUCP> <545@osu-eddie.UUCP>
  1013. Reply-To: cdshaw@watmum.UUCP (Chris Shaw)
  1014. Organization: U of Waterloo, Ontario
  1015. Lines: 27
  1016.  
  1017. --MORE--(32%)
  1018. In article <545@osu-eddie.UUCP> pritch@osu-eddie.UUCP (Norman Pritchett) writes:>cdshaw writes:
  1019. >> VMS is very record-ish, while stream i/o is the unix thing. Unfortunately,
  1020. >> port didn't work because we didn't really spend the effort required to do
  1021. >> the QIO's required to fake stream i/o on VMS. 
  1022. >
  1023. >Huh?  On input Vax-11 C converts records with any attribute (implied
  1024. >carriage control, print carriage control, FORTRAN carriage control, null,
  1025. >and VFC) to stream format (read your "Programming in VAX-11 C" book
  1026. >AA-L370A-TE) so everything always looks like stream files on input.  On
  1027. >output, Vax-11 C creates stream files unless you go through the immense
  1028. >amount of effort to specify otherwise.
  1029. >-- 
  1030. >Norm Pritchett
  1031.  
  1032. Well, it WAS about 1.5 years ago, but if you'd read my posting, you may have
  1033. noticed the word "Kermit" pop up. You might even know that since Kermit
  1034. is a terminal-bashing program, it requires byte-by-byte I/O. GET IT? We didn't
  1035. want buffering. And we didn't really have a clear idea how to turn it off.
  1036. I vaguely recall that either setbuf wasn't available, or it didn't work,
  1037. or it didn't do what we wanted.
  1038.  
  1039. Anyway, that was ages ago, so don't bug me.
  1040.  
  1041. Chris Shaw    watmath!watmum!cdshaw  or  cdshaw@watmath
  1042. University of Waterloo
  1043. In doubt?  Eat hot high-speed death -- the experts' choice in gastric vileness !(Mail) End of article 4859 (of 4956)--what next? [npq] 
  1044.  
  1045. Article 4860 (96 more) in net.lang.c:
  1046. From: david@ukma.UUCP (David Herron, NPR Lover)
  1047. Subject: Re: Cryptic C
  1048. Message-ID: <2076@ukma.UUCP>
  1049. Date: 22 Aug 85 04:20:06 GMT
  1050. Date-Received: 26 Aug 85 05:12:25 GMT
  1051. References: <2913@ncsu.UUCP> <709@brl-tgr.ARPA> <1056@mtgzz.UUCP> <675@gitpyr.UUCP>
  1052. Reply-To: david@ukma.UUCP (David Herron, NPR Lover)
  1053. Organization: Univ. of KY Mathematical Sciences
  1054. Lines: 31
  1055.  
  1056. --MORE--(37%)
  1057. In article <675@gitpyr.UUCP> robert@gitpyr.UUCP (Robert Viduya) writes:
  1058. >In article <1056@mtgzz.UUCP>, dsk@mtgzz.UUCP (d.s.klett) writes:
  1059. ...
  1060. >>      typedef enum { False , True } Boolean;
  1061. ...
  1062. >
  1063. >The problem with enums is that compiler allocate them as ints.  This
  1064. >means 1 wasted byte on a machine with a 16-bit int, 3 wasted bytes on
  1065. >a machine with a 32-bit int and so on and so forth.  All you really
  1066. >need is 1 byte (on most conventional machines).  I personally prefer:
  1067. >
  1068. >    #define    TRUE    1
  1069. >    #define    FALSE   0
  1070. >    typedef    char    bool;
  1071.  
  1072. Well, I personally prefer:
  1073.  
  1074.         #define TRUE (1==1)
  1075.         #define FALSE (1==0)
  1076.         typedef char bool;
  1077.  
  1078. Which is succint, to the point, and *machine*independant*!
  1079.  
  1080. 'sides, constant expressions are calculated at compile time anyway.
  1081. -- 
  1082. --- David Herron
  1083. --- ARPA-> ukma!david@ANL-MCS.ARPA
  1084. --- UUCP-> {ucbvax,unmvax,boulder,oddjob}!anlams!ukma!david
  1085. ---        {ihnp4,decvax,ucbvax}!cbosgd!ukma!david
  1086.  
  1087. Hackin's in me blood.  My mother was known as Miss Hacker before she married!
  1088. (Mail) End of article 4860 (of 4956)--what next? [npq] 
  1089.  
  1090. Article 4861 (95 more) in net.lang.c:
  1091. From: dik@zuring.UUCP
  1092. Subject: Re: More Naughty Bits
  1093. Message-ID: <236@zuring.UUCP>
  1094. Date: 21 Aug 85 23:00:30 GMT
  1095. Date-Received: 26 Aug 85 05:18:19 GMT
  1096. References: <575@brl-tgr.ARPA> <132@rtp47.UUCP> <387@uwmcsd1.UUCP> <944@security.UUCP>
  1097. Reply-To: dik@zuring.UUCP (Dik T. Winter)
  1098. Distribution: net
  1099. Organization: CWI, Amsterdam
  1100. Lines: 12
  1101. Apparently-To: rnews@mcvax.LOCAL
  1102.  
  1103. --MORE--(56%)
  1104. In article <944@security.UUCP> jjg@security.UUCP (Jeff Glass) writes:
  1105. >> (discussion about machines where 0.0 does not have same representation as 0)
  1106. >
  1107. >The CDC Cyber series represents floating-point zero with the (12-bit)
  1108. >exponent zero.  It doesn't matter whether the (48-bit) mantissa is zero
  1109. >or not.
  1110.  
  1111. Not quite, for floating-point multiplication: yes; for floating-point
  1112. addition: no.  (There are numbers such that 2.0*x = 0.0, but x+x /= 0.0)
  1113. -- 
  1114. dik t. winter, cwi, amsterdam, nederland
  1115. UUCP: {seismo|decvax|philabs}!mcvax!dik
  1116. (Mail) End of article 4861 (of 4956)--what next? [npq] 
  1117.  
  1118. Article 4862 (94 more) in net.lang.c:
  1119. From: henry@utzoo.UUCP (Henry Spencer)
  1120. Subject: Re: Cryptic C
  1121. Message-ID: <5884@utzoo.UUCP>
  1122. Date: 19 Aug 85 21:48:35 GMT
  1123. Date-Received: 26 Aug 85 05:20:08 GMT
  1124. References: <2913@ncsu.UUCP>, <709@brl-tgr.ARPA>
  1125. Organization: U of Toronto Zoology
  1126. Lines: 11
  1127.  
  1128. --MORE--(59%)
  1129. >       typedef int     bool;
  1130. >       #define false   0
  1131. >       #define true    1
  1132.  
  1133. It's interesting to note that Kernighan&Plauger use "yes" and "no" rather
  1134. than "true" and "false", and my own reaction is that the code often reads
  1135. better that way.  Now that's something to *really* start a raging debate
  1136. about... :-)
  1137. -- 
  1138.                                 Henry Spencer @ U of Toronto Zoology
  1139.                                 {allegra,ihnp4,linus,decvax}!utzoo!henry
  1140. (Mail) End of article 4862 (of 4956)--what next? [npq] 
  1141.  
  1142. Article 4863 (93 more) in net.lang.c:
  1143. From: roman@persci.UUCP
  1144. Subject: How do I declare...
  1145. Message-ID: <368@persci.UUCP>
  1146. Date: 21 Aug 85 18:18:56 GMT
  1147. Date-Received: 26 Aug 85 06:09:35 GMT
  1148. Organization: Personal Scientific Corporation, Woodinville, WA, USA, Earth...
  1149. Lines: 32
  1150.  
  1151. --MORE--(30%)
  1152. Either I'm missing the perfectly obvious or I've found something
  1153. that's impossible to declare in C, even though it makes sense.  I'm
  1154. trying to implement a simple finite state machine with states
  1155. represented by C functions.  Each state function would accept some
  1156. input value as an argument and return a pointer to the function
  1157. implementing the next state, something like this:
  1158.  
  1159. STATE_FUNC (*state)(),   /* the current state         */
  1160.            *state_1(),   /* a function for each state */
  1161.             ... ,
  1162.            *state_n();
  1163.  
  1164.    for (;;) {
  1165.       state = (*state)(get_input());
  1166.    }
  1167.  
  1168. But how is STATE_FUNC typedef'ed?  It's a pointer to a function which
  1169. returns a pointer to a function which returns a pointer...  Any
  1170. suggestions?
  1171.  
  1172. Obviously, there are other ways to implement a finite state machine,
  1173. and I have already chosen one.  Yet this one is conceptually clean, and
  1174. it seems that there must be some way to do it; plus, this could turn
  1175. out to be a more interesting discussion than i++ vs. i = i + 1...
  1176.  
  1177. -- 
  1178. Bill Roman      {ihnp4,decvax,allegra,...}!uw-beaver!tikal!persci!roman
  1179.  
  1180. Summation, Inc, (formerly Personal Scientific Corporation)
  1181. 18702 142nd Ave NE
  1182. Woodinville, WA 98072
  1183. (206) 486-0991
  1184. (Mail) End of article 4863 (of 4956)--what next? [npq] 
  1185.  
  1186. Article 4864 (92 more) in net.lang.c:
  1187. From: ben@cernvax.UUCP (ben)
  1188. Subject: Xinu -- any experience ??
  1189. Message-ID: <211@cernvax.UUCP>
  1190. Date: 20 Aug 85 20:18:57 GMT
  1191. Date-Received: 26 Aug 85 06:17:23 GMT
  1192. Organization: CERN, Geneva/Switzerland
  1193. Lines: 8
  1194.  
  1195. --MORE--(67%)
  1196.  
  1197.   Does anyone out there have experience of making PRACTICAL
  1198. applications using Douglas Comer's Xinu system?  We are
  1199. interested particularly in any real-time applications for
  1200. 68000's.
  1201.  
  1202.    Ben M. Segal,  CERN-DD,  1211 Geneva 23,  Switzerland
  1203.                   (ben@cernvax via mcvax)
  1204. (Mail) End of article 4864 (of 4956)--what next? [npq] 
  1205.  
  1206. Article 4865 (91 more) in net.lang.c:
  1207. From: kdmoen@watcgl.UUCP (Doug Moen)
  1208. Subject: Re: How do I declare... (recursive typedefs)
  1209. Message-ID: <2407@watcgl.UUCP>
  1210. Date: 24 Aug 85 19:42:50 GMT
  1211. Date-Received: 26 Aug 85 06:42:10 GMT
  1212. References: <368@persci.UUCP>
  1213. Reply-To: kdmoen@watcgl.UUCP (Doug Moen)
  1214. Organization: U of Waterloo, Ontario
  1215. Lines: 38
  1216. Summary: You can't do recursive typedefs
  1217.  
  1218. --MORE--(33%)
  1219. In article <368@persci.UUCP> roman@persci.UUCP writes:
  1220. >Either I'm missing the perfectly obvious or I've found something
  1221. >that's impossible to declare in C, even though it makes sense.  I'm
  1222. >trying to implement a simple finite state machine with states
  1223. >represented by C functions.  Each state function would accept some
  1224. >input value as an argument and return a pointer to the function
  1225. >implementing the next state, something like this:
  1226. >
  1227. >STATE_FUNC (*state)(),   /* the current state         */
  1228. >           *state_1(),   /* a function for each state */
  1229. >            ... ,
  1230. >           *state_n();
  1231. >
  1232. >   for (;;) {
  1233. >      state = (*state)(get_input());
  1234. >   }
  1235. >
  1236. >But how is STATE_FUNC typedef'ed?  It's a pointer to a function which
  1237. >returns a pointer to a function which returns a pointer...  Any
  1238. >suggestions?
  1239.  
  1240. You aren't missing the perfectly obvious.
  1241. Yes, it is impossible to declare in C, even though it makes sense.
  1242.  
  1243. What you want is a recursive typedef:
  1244.         typedef STATE_FUNC (*STATE_FUNC)();
  1245. except that this isn't allowed.
  1246.  
  1247. What you will have to do instead is a kludge:
  1248.         typedef char* (*STATE_FUNC)();
  1249.  
  1250.         for (;;) {
  1251.                 /* Note the cast: */
  1252.                 state = (STATE_FUNC) (*state)(get_input());
  1253.         }
  1254. -- 
  1255. Doug Moen (watmath!watcgl!kdmoen)
  1256. University of Waterloo Computer Graphics Lab
  1257. (Mail) End of article 4865 (of 4956)--what next? [npq] 
  1258.  
  1259. Article 4866 (90 more) in net.lang.c:
  1260. From: pritch@osu-eddie.UUCP (Norman Pritchett)
  1261. Subject: Re: Re: VAX VMS C / Rash attempt at porting Kermit
  1262. Message-ID: <560@osu-eddie.UUCP>
  1263. Date: 24 Aug 85 21:07:38 GMT
  1264. Date-Received: 26 Aug 85 06:50:59 GMT
  1265. References: <488@rdin.UUCP> <249@watmum.UUCP> <545@osu-eddie.UUCP> <260@watmum.UUCP>
  1266. Organization: Ohio State Univ., CIS Dept., Cols, Oh.
  1267. Lines: 24
  1268.  
  1269. --MORE--(40%)
  1270. > Well, it WAS about 1.5 years ago, but if you'd read my posting, you may have
  1271. > noticed the word "Kermit" pop up. You might even know that since Kermit
  1272. > is a terminal-bashing program,it requires byte-by-byte I/O. GET IT? We didn't
  1273. > want buffering. And we didn't really have a clear idea how to turn it off.
  1274. > I vaguely recall that either setbuf wasn't available, or it didn't work,
  1275. > or it didn't do what we wanted.
  1276. > Anyway, that was ages ago, so don't bug me.
  1277. > Chris Shaw    watmath!watmum!cdshaw  or  cdshaw@watmath
  1278. > University of Waterloo
  1279. > In doubt?  Eat hot high-speed death -- the experts' choice in gastric vileness !
  1280.  
  1281. Duh, oops.  Sorry,  every once in a while the connection doesn't quite make
  1282. it.
  1283.  
  1284.  
  1285. -- 
  1286. -----------------------------------
  1287. Norm Pritchett
  1288. UUCP:   cbosgd!osu-eddie!pritch         P.O. Box 3393
  1289. CSNET:  pritch@ohio-state               Columbus OH 43210
  1290. BITNET: TS1703 at OHSTVMA
  1291. Bellnet: (614) 422-0885
  1292. (Mail) End of article 4866 (of 4956)--what next? [npq] 
  1293.  
  1294. Article 4867 (89 more) in net.lang.c:
  1295. From: root@bu-cs.UUCP (Barry Shein)
  1296. Newsgroups: net.lang.c,net.unix-wizards
  1297. Subject: Re: Re: how has C bitten you?
  1298. Message-ID: <607@bu-cs.UUCP>
  1299. Date: 24 Aug 85 06:58:57 GMT
  1300. Date-Received: 26 Aug 85 06:51:44 GMT
  1301. References: <302@brl-tgr.ARPA> <471@baylor.UUCP>, <148@chinet.UUCP>
  1302. Organization: Boston Univ Comp. Sci.
  1303. Lines: 16
  1304.  
  1305. --MORE--(56%)
  1306. Not really a bite, but I remember when I was first learning C
  1307. I was quite bewildered by the fact that you couldn't really
  1308. declare your own 'argv', that is, you couldn't declare an
  1309. array of pointers to fixed length buffers except perhaps by:
  1310.  
  1311. char *myargv[] = {
  1312.         "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0",
  1313.         "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0",
  1314.  
  1315.         etc
  1316.  
  1317. I mean, argv seemed kinda holy to me, disturbing.
  1318.  
  1319.         -Barry Shein, Boston University
  1320.  
  1321. P.S. I know argv is var length, but that would be even harder to declare!
  1322. (Mail) End of article 4867 (of 4956)--what next? [npq] 
  1323.  
  1324. Article 4868 (88 more) in net.lang.c:
  1325. From: ED@MIT-MC.ARPA (Ed Schwalenberg)
  1326. Subject: Good C compilers for 68000
  1327. Message-ID: <862@brl-tgr.ARPA>
  1328. Date: 21 Aug 85 21:11:41 GMT
  1329. Date-Received: 26 Aug 85 06:59:41 GMT
  1330. Sender: news@brl-tgr.ARPA
  1331. Lines: 16
  1332.  
  1333. --MORE--(34%)
  1334. We've been using Microsoft's Xenix on Microbar hardware to develop and
  1335. run large C applications.  We have reached the point where our programs
  1336. are too large and too complex for the compiler provided with Xenix.
  1337. Things like limits on the number of #defines, limits on the nesting of
  1338. structures, and the like are giving us fits.  And the code produced by
  1339. this compiler (a descendent of the MIT port of the portable compiler)
  1340. is awful.
  1341.  
  1342. Are there better compilers out there?  Where do I get them?  Microsoft
  1343. refuses to talk with us since Microbar as OEM is supposed to handle
  1344. such things.  Microbar is too busy trying to stay afloat.  Tartan only
  1345. has products for the Vax.  We tried a Whitesmiths product several years
  1346. ago which was even worse, as was a compiler from a company called Alcyon.
  1347. I've heard rumors about the "Green Hills" compiler, but have been unable
  1348. to find out how to get in touch with them.  Any help would be appreciated.
  1349. Please reply to me directly, as I don't subscribe to these lists.
  1350. (Mail) End of article 4868 (of 4956)--what next? [npq] 
  1351.  
  1352. Article 4871 (85 more) in net.lang.c:
  1353. From: cottrell@nbs-vms.ARPA
  1354. Subject: Cryptic Code
  1355. Message-ID: <870@brl-tgr.ARPA>
  1356. Date: 21 Aug 85 23:26:55 GMT
  1357. Date-Received: 26 Aug 85 07:01:21 GMT
  1358. Sender: news@brl-tgr.ARPA
  1359. Lines: 17
  1360.  
  1361. --MORE--(55%)
  1362. /*
  1363. > Does anyone out there support the author by saying that Version 3 of
  1364. > 'strcpy' is better than Version 2?
  1365.  
  1366. Definitely. You are thinking in terms of another language instead of
  1367. thinking in C. This is like trying to speak french while translating
  1368. to/from english as you go, n'est ce pas?
  1369.  
  1370. > Bob Crane
  1371. > !tektronix!tektools!bobc
  1372. > (503)627-5379
  1373.  
  1374. or you can always try:  stalag13!hogan  :-)
  1375.  
  1376.         jim             cottrell@nbs
  1377. */
  1378. ------
  1379. (Mail) End of article 4871 (of 4956)--what next? [npq] 
  1380.  
  1381. Article 4873 (83 more) in net.lang.c:
  1382. From: cottrell@nbs-vms.ARPA
  1383. Subject: C bites Dog!
  1384. Message-ID: <872@brl-tgr.ARPA>
  1385. Date: 22 Aug 85 01:10:37 GMT
  1386. Date-Received: 26 Aug 85 07:01:54 GMT
  1387. Sender: news@brl-tgr.ARPA
  1388. Lines: 53
  1389.  
  1390. --MORE--(20%)
  1391. /*
  1392. > > > ???:
  1393. > > >           if (sv > score);   <----- note extraneous semi-colon
  1394. > > >                   score = sv;
  1395. > > Doug Gwyn:
  1396. > > This sort of thing makes me think that a few extra keywords
  1397. > > are called for programming languages like this.  E.g.
  1398. > >     if <bool_expr> then <stmt> fi
  1399. > >     while <bool_expr> do <stmt> od
  1400. > > Something to keep in mind when you design an Algol-like language.
  1401. > ICK ICK ICK! I hate languages that do that. Ever considered using "cb" as a
  1402. > debugging tool? I have an MS-DOS version if anyone wants it...
  1403. > -- 
  1404. >       Peter da Silva (the mad Australian werewolf)
  1405. >               UUCP: ...!shell!neuro1!{hyd-ptd,baylor,datafac}!peter
  1406. >               MCI: PDASILVA; CIS: 70216,1076
  1407.  
  1408. Dear Peter,
  1409.  
  1410.         Welcome to the `Let's Disagree with Doug' club! Unfortunately,
  1411. I am forced to agree with him here. CB (& INDENT) is A Good Thing,
  1412. but since I am such a wonderful coder (:-) I rarely use them. What they
  1413. really are useful for is importing code written by cretins. Also, I
  1414. probably disagree slightly with the output of those formatters. What
  1415. would you do, compare the output of `cb' with the original? Takes
  1416. lots of time & can be visually overlooked.
  1417.  
  1418.         Anyway, to get back to the point, you come to realize that in
  1419.  
  1420.                 if <exp> then <stmt> else <stmt> fi
  1421.  
  1422. the parens around <exp> are unneccesary. And the `fi' makes sure that
  1423. all the elses nest with the correct `if'. The Bourne shell has the
  1424. following definitions, (which many peole dislike, but I think they're OK)
  1425.  
  1426.         #define IF      if(
  1427.         #define THEN    ){
  1428.         #define ELSE    }else{
  1429.         #define FI      }
  1430.  
  1431. The point is, you need at least 4 tokens (or a `one-statement' model)
  1432. to delimit the three parts of an `if' from each other and the outside.
  1433. C uses four (not counting semicolons)in the short form
  1434. (if (e) s1; else s2;) and eight in the long form
  1435. (if (e) { s1; } else { s2; }). And let's get rid of those semicolons 
  1436. too! A newline should imply one. Two statements on a line would need
  1437. an explicit one. An escaped newline would continue to the next line.
  1438. Yeah, I know, write my own language!
  1439.  
  1440.         jim             cottrell@nbs
  1441. */
  1442. ------
  1443. (Mail) End of article 4873 (of 4956)--what next? [npq] 
  1444.  
  1445. Article 4875 (81 more) in net.lang.c:
  1446. From: mikes@3comvax.UUCP (Mike Shannon)
  1447. Subject: C bites / programming style
  1448. Message-ID: <165@3comvax.UUCP>
  1449. Date: 23 Aug 85 17:37:13 GMT
  1450. Date-Received: 26 Aug 85 07:39:49 GMT
  1451. Distribution: net
  1452. Organization: 3Com Corp; Mountain View, CA
  1453. Lines: 14
  1454.  
  1455. --MORE--(51%)
  1456. With regard to:
  1457.         if(condition);          /* the bug is the seimcolon on this line */
  1458.                 statement;      /* this statement was intended to be
  1459.                                  * executed iff the condition was true
  1460.                                  */
  1461. --------------------
  1462.         I avoid getting bitten in this way by ALWAYS using {}'s after
  1463. if, while, etc.  Even when I have a null statement as the body of an
  1464. while or for, I do it this way:
  1465.         for(i = 0; i < MAX; i++) {
  1466.         }
  1467. Always using braces with if/else also removes ambiguity concerning
  1468. "which if an else belongs to."
  1469.                                 -Michael Shannon (hplabs!oliveb!3comvax!mikes)
  1470. (Mail) End of article 4875 (of 4956)--what next? [npq] 
  1471.  
  1472. Article 4876 (80 more) in net.lang.c:
  1473. From: eppstein@columbia.UUCP (David Eppstein)
  1474. Subject: Re: How do I declare...
  1475. Message-ID: <969@columbia.UUCP>
  1476. Date: 25 Aug 85 00:08:06 GMT
  1477. Date-Received: 26 Aug 85 22:58:10 GMT
  1478. References: <368@persci.UUCP>
  1479. Reply-To: eppstein@columbia.UUCP (David Eppstein)
  1480. Organization: Columbia University
  1481. Lines: 9
  1482.  
  1483. --MORE--(56%)
  1484. In article <368@persci.UUCP> roman@persci.UUCP writes:
  1485. > Either I'm missing the perfectly obvious or I've found something
  1486. > that's impossible to declare in C, even though it makes sense.  I'm
  1487. > trying to implement a simple finite state machine with states
  1488. > represented by C functions.  Each state function would accept some
  1489. > input value as an argument and return a pointer to the function
  1490. > implementing the next state...
  1491.  
  1492. It works if you imbed them in a struct.  Kind of ugly though.
  1493. (Mail) End of article 4876 (of 4956)--what next? [npq] 
  1494.  
  1495. Article 4877 (79 more) in net.lang.c:
  1496. From: rlk@chinet.UUCP (Richard L. Klappal)
  1497. Subject: Re: Cryptic C
  1498. Message-ID: <156@chinet.UUCP>
  1499. Date: 25 Aug 85 08:38:34 GMT
  1500. Date-Received: 26 Aug 85 22:59:32 GMT
  1501. References: <2913@ncsu.UUCP> <709@brl-tgr.ARPA> <1056@mtgzz.UUCP> <2076@ukma.UUCP> <685@gitpyr.UUCP>
  1502. Reply-To: rlk@chinet.UUCP (Richard L. Klappal)
  1503. Organization: chinet, Public Access UN*X, Chicago
  1504. Lines: 52
  1505. Summary: 
  1506.  
  1507. --MORE--(26%)
  1508. In article <685@gitpyr.UUCP> robert@gitpyr.UUCP (Robert Viduya) writes:
  1509. >In article <2076@ukma.UUCP>, david@ukma.UUCP (David Herron, NPR Lover) writes:
  1510. >> In article <675@gitpyr.UUCP> robert@gitpyr.UUCP (Robert Viduya) writes:
  1511. >> >
  1512. >> > ... I personally prefer:
  1513. >> >
  1514. >> >    #define TRUE    1
  1515. >> >    #define FALSE   0
  1516. >> >    typedef char    bool;
  1517. >> 
  1518. >> Well, I personally prefer:
  1519. >> 
  1520. >>      #define TRUE (1==1)
  1521. >>      #define FALSE (1==0)
  1522. >>      typedef char bool;
  1523. >> 
  1524. >> Which is succint, to the point, and *machine*independant*!
  1525. >> 
  1526. >
  1527. >Oh?  On what machine is (1==1) equal to 0, or (1==0) not equal to 0?  In
  1528. >section 7.6 (Relational operators, Appendix A - C Reference Manual from
  1529. >K&R's The C Programming Language), it explicitly states that the logical
  1530. >operators all yield 0 if the relation is false and 1 if the relation is
  1531. >true.  Nothing is mentioned about possible variations due to implementation
  1532. >machine differences.
  1533. >
  1534. >                               robert
  1535. >-- 
  1536. >Robert Viduya                                                  01111000
  1537. Maybe not 'machine independent' in C, but the logic will
  1538. be 'language independent' (using the appropriate equality operator).
  1539.  
  1540. I've had to debug an awful lot of assembly language where
  1541. a cpu 'Z' flag (zero-flag) was used as TRUE.  About like strcmp
  1542. returns 0 if two strings are the same so that you cannot extend
  1543. the concept 
  1544.  
  1545.         if (string1==string2) {...}
  1546.  
  1547. that works in F77, PL/I, BASIC, etc.
  1548.  
  1549.  
  1550.  
  1551. Richard Klappal
  1552.  
  1553. UUCP:           ..!ihnp4!chinet!uklpl!rlk  | "Money is truthful.  If a man
  1554. MCIMail:        rklappal                   | speaks of his honor, make him
  1555. Compuserve:     74106,1021                 | pay cash."
  1556. USPS:           1 S 299 Danby Street       | 
  1557.                 Villa Park IL 60181        |    Lazarus Long 
  1558. TEL:            (312) 620-4988             |        (aka R. Heinlein)
  1559. -------------------------------------------------------------------------
  1560. (Mail) End of article 4877 (of 4956)--what next? [npq] 
  1561.  
  1562. Article 4878 (78 more) in net.lang.c:
  1563. From: ark@alice.UucP (Andrew Koenig)
  1564. Subject: Re: Cryptic C
  1565. Message-ID: <4209@alice.UUCP>
  1566. Date: 25 Aug 85 15:38:12 GMT
  1567. Date-Received: 26 Aug 85 23:02:42 GMT
  1568. References: <2083@ukma.UUCP>
  1569. Organization: Bell Labs, Murray Hill
  1570. Lines: 13
  1571.  
  1572. --MORE--(46%)
  1573. > I have always thought that to be a machine dependancy (the value of true and
  1574. > false).  Maybe I'm wrong.  But, different machines DO have different ideas
  1575. > of which is true and false (at the assembler level).  And it is simply
  1576. > a convention.
  1577.  
  1578. You are wrong: the value of true and false in C is defined as part of
  1579. the language:
  1580.  
  1581. When I write    if(exp) foo(); else bar();   foo is called if exp is
  1582. nonzero and bar is called if exp is zero.
  1583.  
  1584. The result of relational operators, &&, ||, and ! is always 1 or 0
  1585. (not some random machine-dependent value or zero).
  1586. (Mail) End of article 4878 (of 4956)--what next? [npq] 
  1587.  
  1588. Article 4879 (77 more) in net.lang.c:
  1589. From: arnold@gatech.CSNET (Arnold Robbins)
  1590. Subject: Re: How do I declare...
  1591. Message-ID: <1001@gatech.CSNET>
  1592. Date: 25 Aug 85 17:38:54 GMT
  1593. Date-Received: 27 Aug 85 00:42:07 GMT
  1594. References: <368@persci.UUCP> <159@rtp47.UUCP>
  1595. Organization: Pr1mebusters!
  1596. Lines: 23
  1597.  
  1598. --MORE--(39%)
  1599.  
  1600.  
  1601. Article 4880 (76 more) in net.lang.c:
  1602. From: ado@elsie.UUCP (Arthur David Olson)
  1603. Subject: Re: Cryptic C
  1604. Message-ID: <5208@elsie.UUCP>
  1605. Date: 24 Aug 85 16:21:43 GMT
  1606. Date-Received: 27 Aug 85 03:16:26 GMT
  1607. References: <2913@ncsu.UUCP> <709@brl-tgr.ARPA> <1056@mtgzz.UUCP> <2076@ukma.UUCP> <685@gitpyr.UUCP>
  1608. Organization: NIH-LEC, Bethesda, MD
  1609. Lines: 29
  1610. Summary: The good news and the other news about (1==1)
  1611.  
  1612. --MORE--(44%)
  1613. > > > . . .I personally prefer:
  1614. > > >
  1615. > > >    #define        TRUE    1
  1616. > > >    #define        FALSE   0
  1617. > > > . . .
  1618. > > . . .I personally prefer:
  1619. > > 
  1620. > >     #define TRUE (1==1)
  1621. > >     #define FALSE (1==0)
  1622. > > . . .
  1623. > Oh?  On what machine is (1==1) equal to 0, or (1==0) not equal to 0? . . .
  1624.  
  1625. Yes, the good book (K&R) says that (1==1) is always 1.
  1626. The advantage of the second approach above is that it obviates the need to
  1627. remember this fact.  The disadvantage of the second approach above is that it
  1628. gives "lint" fits ("constant in conditional context").
  1629.  
  1630. As for what *I* prefer:
  1631.  
  1632.         #ifndef TRUE
  1633.         #define TRUE    (1)
  1634.         #define FALSE   (0)
  1635.         #endif
  1636.  
  1637. where the parenthesized definitions match those in "curses.h" to ensure that
  1638. if a reference to "curses.h" appears after the above lines I won't get a
  1639. "macro redefined to a different value" diagnostic from the C preprocessor.
  1640.  
  1641.                                 --ado
  1642. (Mail) End of article 4880 (of 4956)--what next? [npq] 
  1643.  
  1644. Article 4881 (75 more) in net.lang.c:
  1645. From: landauer@drivax.UUCP (Doug Landauer)
  1646. Subject: Re: Cryptic C (Actually typedef ? boolean;)
  1647. Message-ID: <212@drivax.UUCP>
  1648. Date: 20 Aug 85 19:08:04 GMT
  1649. Date-Received: 27 Aug 85 08:32:23 GMT
  1650. References: <2913@ncsu.UUCP> <709@brl-tgr.ARPA>
  1651. Organization: Digital Research, Monterey, CA
  1652. Lines: 17
  1653.  
  1654. --MORE--(56%)
  1655. Doug Gwyn says:
  1656. > I am pretty conservative when it comes to defining one's own
  1657. > language extensions, this one seems like a winner:
  1658. >       typedef int     bool;
  1659. >       #define false   0
  1660. >       #define true    1
  1661.  
  1662. My favorite way to do this one is
  1663.         typedef enum { false, true } boolean ;
  1664.  
  1665. It provides a little more type checking than your typedef.
  1666. --
  1667.                         -- Doug Landauer --
  1668.         ...[ ihnp4 | mot | ucscc | amdahl ] !drivax!landauer
  1669.                 -- "I survived the DRI layoffs." --
  1670.                         -- "(So far!)" --
  1671. (Mail) End of article 4881 (of 4956)--what next? [npq] 
  1672.  
  1673. Article 4882 (74 more) in net.lang.c:
  1674. From: alexis@reed.UUCP (Alexis Dimitriadis)
  1675. Subject: Re: C bites Dog!
  1676. Message-ID: <1835@reed.UUCP>
  1677. Date: 25 Aug 85 05:25:22 GMT
  1678. Date-Received: 27 Aug 85 10:34:26 GMT
  1679. References: <872@brl-tgr.ARPA>
  1680. Reply-To: alexis@reed.UUCP (Alexis Dimitriadis)
  1681. Organization: Reed College, Portland, Oregon
  1682. Lines: 70
  1683. Summary: 
  1684.  
  1685. --MORE--(16%)
  1686. > > > >                 if (sv > score);   <----- note extraneous semi-colon
  1687. > > > >                         score = sv;
  1688. > > ICK ICK ICK! I hate languages that do that. Ever considered using "cb" as a
  1689. > > debugging tool? I have an MS-DOS version if anyone wants it...
  1690. > [...]  What
  1691. > would you do, compare the output of `cb' with the original? Takes
  1692. > lots of time & can be visually overlooked.
  1693.  
  1694.   Here is an idea I've had on the back burner for while: How about a
  1695. program that checks the formatting of the source code for consistency?
  1696.   - Take a C beautifier.  
  1697.   - Modify the lexical analyzer so it passes the amount of indentation
  1698.     preceding the line each input statement is on.
  1699.   - Now for each statement, check the _relative_ indentation.  A normal
  1700.     statement should be indented exactly as far as the previous statement;
  1701.     the subordinate part of an "if" or a loop should be further indented,
  1702.     or be on the same line; lines that contain continuation of an expression
  1703.     can start anywhere, and do not affect the expected indent; etc.
  1704.   - If the input disagrees, give a diagnostic.
  1705.  
  1706.   This should catch things like
  1707.     if (tv.set == junk);
  1708.         turn(off);
  1709. or even
  1710.     while (cat == away)
  1711.         mice(dance);
  1712.         cheese--;
  1713. since the "while" should be aligned with the "cheese".  Of course,
  1714. it would be powerless with
  1715.     if (procter & gamble); chips++;
  1716. unless you put in a rule about multiple equal-level statements on the
  1717. same line, which would create problems with macro expansion, etc.
  1718.  
  1719.   Now I haven't started work on this yet, (first I finish my thesis),
  1720. but it seems it could be made to work consistently, and without a lot
  1721. of false alarms.  However, a friend who may know better disagrees.
  1722. Are there really impossible obstacles to the task?  I know the lexical
  1723. analyzer would have to keep track of the offset, and probably line
  1724. number, of every token, but that's no big deal.
  1725.  
  1726.   Could it cope with the thousands of indenting styles?  I think the
  1727. test is general anough to cope with anything.  Since there are so many
  1728. places braces can be, they could be just ingored.
  1729.  
  1730.   Is it a pipe dream? Has it been done before?  (If it has, it must be
  1731. a well kept secret!).  What should I watch out for? Whose code would
  1732. it gag on?  If you have the answers to any of this, (or even some good
  1733. questions), I would appreciate hearing from you.
  1734.  
  1735.   Finally, I apologize for the length of this, and please! none of the
  1736. above condones of condemns any particular style of indenting, the
  1737. subject has been trashed to death anyway.  I have kept the results of
  1738. the indenting style survey, I will mail them to anyone interested.
  1739.  
  1740. Thanks for your attention,
  1741. Alexis Dimitriadis 
  1742.  
  1743.   PS. I have lost the name of the person who conducted the survey.  If
  1744. you still have the "other style" answers, could you send me a list?
  1745. -- 
  1746. _______________________________________________
  1747.   As soon as I get a full time job, the opinions expressed above
  1748. will attach themselves to my employer, who will never be rid of
  1749. them again.
  1750.  
  1751.              alexis @ reed
  1752.  
  1753.                  ...teneron! \
  1754. ...seismo!ihnp4! - tektronix! - reed.UUCP
  1755.      ...decvax! /
  1756. (Mail) End of article 4882 (of 4956)--what next? [npq] 
  1757.  
  1758. Article 4883 (73 more) in net.lang.c:
  1759. From: david@ukma.UUCP (David Herron, NPR Lover)
  1760. Subject: Re: Cryptic C
  1761. Message-ID: <2083@ukma.UUCP>
  1762. Date: 25 Aug 85 06:37:23 GMT
  1763. Date-Received: 27 Aug 85 11:06:59 GMT
  1764. References: <2913@ncsu.UUCP> <709@brl-tgr.ARPA> <1056@mtgzz.UUCP> <2076@ukma.UUCP> <685@gitpyr.UUCP>
  1765. Reply-To: david@ukma.UUCP (David Herron, NPR Lover)
  1766. Organization: Univ. of KY Mathematical Sciences
  1767. Lines: 47
  1768.  
  1769. --MORE--(22%)
  1770. In article <685@gitpyr.UUCP> robert@gitpyr.UUCP (Robert Viduya) writes:
  1771. >In article <2076@ukma.UUCP>, david@ukma.UUCP (David Herron, NPR Lover) writes:
  1772. >> Well, I personally prefer:
  1773. >> 
  1774. >>      #define TRUE (1==1)
  1775. >>      #define FALSE (1==0)
  1776. >>      typedef char bool;
  1777. >> 
  1778. >> Which is succint, to the point, and *machine*independant*!
  1779. >> 
  1780. >
  1781. >Oh?  On what machine is (1==1) equal to 0, or (1==0) not equal to 0?  In
  1782. >section 7.6 (Relational operators, Appendix A - C Reference Manual from
  1783. >K&R's The C Programming Language), it explicitly states that the logical
  1784. >operators all yield 0 if the relation is false and 1 if the relation is
  1785. >true.  Nothing is mentioned about possible variations due to implementation
  1786. >machine differences.
  1787.  
  1788. I don't particularly care if it's defined to be machine independant already.
  1789.  
  1790. I have always thought that to be a machine dependancy (the value of true and
  1791. false).  Maybe I'm wrong.  But, different machines DO have different ideas
  1792. of which is true and false (at the assembler level).  And it is simply
  1793. a convention.
  1794.  
  1795. Still though, #define TRUE (1==1) is very obvious, to the point, correct,
  1796. proper, and all sorts of things.  And it doesn't require one to know
  1797. that detail about C that the convention is ~0 == TRUE and 0 == FALSE.
  1798.  
  1799. When I'm writing C I think of it has a *high*level*language*.  Not as 
  1800. simply one step away from assembler.  The difference between C and other 
  1801. *high*level*languages* is that it gives you precise control over an 
  1802. idealized machine.  This is what confuses most people about C, because
  1803. it can *feel* like assembler.  Especially when they've learned it on a 
  1804. PDP-11 and think like an assembly programmer.
  1805.  
  1806. But C gives you all these operators which allow you to define things
  1807. machine independantly rather than hardcoding values.  Obviously I mean
  1808. casts and the sizeof operator.  Also arithmetic to pointers.  So why not
  1809. TRUE and FALSE?
  1810. -- 
  1811. --- David Herron
  1812. --- ARPA-> ukma!david@ANL-MCS.ARPA
  1813. --- UUCP-> {ucbvax,unmvax,boulder,oddjob}!anlams!ukma!david
  1814. ---        {ihnp4,decvax,ucbvax}!cbosgd!ukma!david
  1815.  
  1816. Hackin's in me blood.  My mother was known as Miss Hacker before she married!
  1817. (Mail) End of article 4883 (of 4956)--what next? [npq] 
  1818.  
  1819. Article 4884 (72 more) in net.lang.c:
  1820. From: guy@sun.uucp (Guy Harris)
  1821. Subject: Re: how has C bitten you?
  1822. Message-ID: <2702@sun.uucp>
  1823. Date: 24 Aug 85 22:43:37 GMT
  1824. Date-Received: 28 Aug 85 03:02:59 GMT
  1825. References: <228@investor.UUCP> <132@mcgill-vision.UUCP>
  1826. Organization: Sun Microsystems, Inc.
  1827. Lines: 62
  1828.  
  1829. --MORE--(20%)
  1830. >   [ ... ]
  1831. > >     if(telno){              /*  should be if(*telno)  */
  1832. >   [ ... ]
  1833. > > Print statements showed the telno was being handed to the routine,
  1834. > > but the if said nothing was there.  Turns out, on my system, the
  1835. > > address of telno is NULL.  I needed to check the contents not the
  1836. > > address!
  1837. > Gee....and I thought a zero pointer was guaranteed not to point to
  1838. > anything valid (K&R says this).
  1839.  
  1840. All valid implementations of C guarantee this.  Obviously, the
  1841. implementation of C that this was done on is not valid.  He should complain
  1842. to the vendor.  (Yes, there have been such implementations; one well-known
  1843. chip maker's first UNIX release didn't put the necessary shim at data
  1844. location 0 on a separate I&D space program.  They fixed it shortly
  1845. afterwards.)
  1846.  
  1847. > Or is NULL not a zero?!  No, you are comparing to 0 not NULL.
  1848.  
  1849. If you compare a pointer against 0, the actual code compiled compares it
  1850. against a null pointer.  NULL *is* 0, if you're talking from the standpoint
  1851. of "what does the '#define' in <stdio.h> and other places say":
  1852.  
  1853.         /*      @(#)stdio.h 1.2 85/01/21 SMI; from UCB 1.4 06/30/83     */
  1854.  
  1855.         ...
  1856.  
  1857.         #define NULL    0
  1858.  
  1859. (and you'll find the same thing in V7, 4.2, 4.3, S3, S5, ...).  In any
  1860. context where it is known to the compiler that something is supposed to be a
  1861. pointer to a specific data type, any zero that appears there is treated as a
  1862. null pointer of the type "pointer to that data type" (obviously, not a null
  1863. pointer to an object of that data type, since a null pointer can't point to
  1864. anything).  These contexts include comparisons and assignments, so the two
  1865. assignments in
  1866.  
  1867.         register struct frobozz *p;
  1868.  
  1869.         p = 0;
  1870.         p = (struct frobozz *)0;
  1871.  
  1872. are equivalent and the two comparisons in
  1873.  
  1874.         if (p == 0)
  1875.                 foo();
  1876.         if (p == (struct frobozz *)0)
  1877.                 foo();
  1878.  
  1879. are equivalent.  Procedure calls, however, are not such a context, so the
  1880. two procedure calls in
  1881.  
  1882.         bar(0);
  1883.         bar((struct frobozz *)0);
  1884.  
  1885. are very definitely *not* equivalent.  In ANSI Standard C, there is a syntax
  1886. to specify that "bar" takes an argument of type "struct frobozz *"; if you
  1887. declared "bar" in such a manner, the two procedure calls would be equivalent.
  1888.  
  1889.         Guy Harris
  1890. (Mail) End of article 4884 (of 4956)--what next? [npq] 
  1891.  
  1892.  
  1893. Article 4886 (70 more) in net.lang.c:
  1894. From: gwyn@brl-tgr.ARPA (Doug Gwyn <gwyn>)
  1895. Subject: Re: Cryptic C
  1896. Message-ID: <904@brl-tgr.ARPA>
  1897. Date: 22 Aug 85 21:57:19 GMT
  1898. Date-Received: 28 Aug 85 03:03:49 GMT
  1899. References: <2913@ncsu.UUCP> <709@brl-tgr.ARPA> <1056@mtgzz.UUCP>
  1900. Organization: Ballistic Research Lab
  1901. Lines: 3
  1902.  
  1903. --MORE--(77%)
  1904. The reason I didn't use char or enum for boolean data definition
  1905. is that that is not how C actually works.  Int is a more accurate
  1906. representation of the current state of affairs.
  1907. (Mail) End of article 4886 (of 4956)--what next? [npq] 
  1908.  
  1909. Article 4887 (69 more) in net.lang.c:
  1910. From: gwyn@brl-tgr.ARPA (Doug Gwyn <gwyn>)
  1911. Subject: Re: Cryptic C
  1912. Message-ID: <905@brl-tgr.ARPA>
  1913. Date: 22 Aug 85 21:59:24 GMT
  1914. Date-Received: 28 Aug 85 03:03:56 GMT
  1915. References: <2913@ncsu.UUCP>, <709@brl-tgr.ARPA> <5884@utzoo.UUCP>
  1916. Organization: Ballistic Research Lab
  1917. Lines: 5
  1918.  
  1919. --MORE--(72%)
  1920. > It's interesting to note that Kernighan&Plauger use "yes" and "no" rather
  1921. > than "true" and "false", ...
  1922.  
  1923. Yes, but the conventional use in symbolic logic is true/false.
  1924. One is not always asking a natural yes/no question of a predicate.
  1925. (Mail) End of article 4887 (of 4956)--what next? [npq] 
  1926.  
  1927. Article 4888 (68 more) in net.lang.c:
  1928. From: mbr@aoa.UUCP (Mark Rosenthal)
  1929. Subject: Suggestion to enhance code readability
  1930. Message-ID: <255@aoa.UUCP>
  1931. Date: 22 Aug 85 23:21:32 GMT
  1932. Date-Received: 28 Aug 85 03:05:00 GMT
  1933. References: <11457@brl-tgr.ARPA> <68@ucbcad.UUCP> <1693@reed.UUCP>
  1934. Distribution: net
  1935. Organization: Adaptive Optics Assoc., Cambridge, Mass. USA
  1936. Lines: 30
  1937.  
  1938. --MORE--(33%)
  1939. Although our site has been receiving articles for the past few months,
  1940. articles posted to the net have not been getting distributed until recently.
  1941. The following is a reposting of an article I sent out quite some time ago.
  1942. I believe it never made it to the net at large.  Apologies if you have seen
  1943. this before.
  1944. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1945.  
  1946. Alexis Dimitriadis (alexis @ reed) writes:
  1947.  
  1948. >   Expressions like "while (var++) ;" introduce problems that take
  1949. > (bitter) experience before they can be handily detected, even if the
  1950. > reader is familiar with the semantics of the expression.  That is the
  1951. > real reason it takes a seasoned C programmer to debug seasoned C code.
  1952.  
  1953. Since every simple C statement ends with a ";", it is easy to misread
  1954. the ";" in the above as a terminator for the while statement, rather
  1955. than a terminator for a null statement controlled by the while.  Placing
  1956. the ";" on the same line as the while makes this misinterpretation very
  1957. likely.  That is why I came up with the following (equivalent) construction,
  1958. which I have been using for several years.  I believe it enhances readability.
  1959. But then, I have weird tastes.
  1960.  
  1961.         while (var++)
  1962.             { }
  1963.  
  1964.  
  1965. -- 
  1966.  
  1967.         Mark of the Valley of Roses
  1968.         ...!{decvax,linus,ima,ihnp4}!bbncca!aoa!mbr
  1969. (Mail) End of article 4888 (of 4956)--what next? [npq] 
  1970.  
  1971. Article 4889 (67 more) in net.lang.c:
  1972. From: ee161bep@sdcc3.UUCP (Paul Van de Graaf)
  1973. Subject: Re: C bites Dog!
  1974. Message-ID: <2968@sdcc3.UUCP>
  1975. Date: 24 Aug 85 10:33:25 GMT
  1976. Date-Received: 28 Aug 85 03:07:51 GMT
  1977. References: <872@brl-tgr.ARPA>
  1978. Reply-To: ee161bep@sdcc3.UUCP (Paul Van de Graaf{|stu)
  1979. Organization: U.C. San Diego, Academic Computer Center
  1980. Lines: 28
  1981.  
  1982. --MORE--(27%)
  1983. In article <872@brl-tgr.ARPA> cottrell@nbs-vms.ARPA writes:
  1984. >The point is, you need at least 4 tokens (or a `one-statement' model)
  1985. >to delimit the three parts of an `if' from each other and the outside.
  1986. >C uses four (not counting semicolons)in the short form
  1987. >(if (e) s1; else s2;) and eight in the long form
  1988. >(if (e) { s1; } else { s2; }). And let's get rid of those semicolons 
  1989. >too! A newline should imply one. Two statements on a line would need
  1990. >an explicit one. An escaped newline would continue to the next line.
  1991. >Yeah, I know, write my own language!
  1992. >
  1993. >       jim             cottrell@nbs
  1994.  
  1995.         Couldn't agree with Jim more!  Especially on the no semi-colon point.
  1996. I use Action! (a C/Pascal/Basic derivative) on my Atari, and it has this
  1997. feature.  If Action! had all of C's operators, had more reasonable data types
  1998. (better struct/unions etc.), AND supported recursion, I'd never look back.
  1999. Action also has the if <> then <> fi style bracketing which I suppose was
  2000. inspired by the Bourne shell.  I personally don't like the case .. esac stuff
  2001. in the Bourne shell, but I can't understand why C programmers are so concerned
  2002. about typing 2 to 5 letter keywords instead of (, ), {, and }.  I don't type
  2003. special characters very well, and I think it's because of having to hit that
  2004. <shift> key.  The QWERTY system is at its best when typing alphas; anything
  2005. else slows you down, especially when you have to look for the "weird" keys
  2006. that various brain-damaged manufacturers put in all kinds of crazy positions.
  2007. I'm ready for something beyond C, and I don't mean C++ or Ada.  If no one
  2008. obliges all just have to do as Jim says and write my own.
  2009.  
  2010. Paul van de Graaf       sdcsvax!sdcc3!ee161bep          U. C. San Diego
  2011. (Mail) End of article 4889 (of 4956)--what next? [npq] 
  2012.  
  2013.  
  2014. Article 4893 (63 more) in net.lang.c:
  2015. From: roy@phri.UUCP (Roy Smith)
  2016. Subject: Re: C bites / programming style [if (cond); statement;]
  2017. Message-ID: <418@phri.UUCP>
  2018. Date: 25 Aug 85 19:11:01 GMT
  2019. Date-Received: 28 Aug 85 04:16:51 GMT
  2020. References: <165@3comvax.UUCP>
  2021. Distribution: net
  2022. Organization: Public Health Research Inst. (NY, NY)
  2023. Lines: 62
  2024.  
  2025. --MORE--(16%)
  2026. >       I avoid getting bitten in this way by ALWAYS using {}'s after
  2027. > if, while, etc.  Even when I have a null statement as the body [...]
  2028. > -Michael Shannon (hplabs!oliveb!3comvax!mikes)
  2029.  
  2030.         Since I was the original poster of this particular bite, let me
  2031. add a few random comments.  First off, I'm really kind of amazed how much
  2032. discussion this is getting.  I wish people would pay this much attention
  2033. when I do things correctly!
  2034.  
  2035.         Oddly enough, part of the bite was from emacs.  Since the code in
  2036. question was repeated several times with small changes, I wrote it once and
  2037. used a macro to duplicate and modify it each time.  My real goof was in
  2038. defining the emacs macro.  I somehow dragged the extra semi-colon along
  2039. causing an error I probably wouldn't have made if I wrote each fragment by
  2040. hand.  Shows me to try and be clever.
  2041.  
  2042.         I put null loop-bodies on a separate line like in the following
  2043. example.  You all know how I write null if-bodies. :-)
  2044.  
  2045.                 while (eatup() != '\n')
  2046.                         ;
  2047.  
  2048.         If the body of the [whatever] is a single simple statement, I leave
  2049. out the braces and do something like the following (I'm using "simple" in
  2050. the generic sense, not strictly as defined by the C grammer):
  2051.  
  2052.         if (foo >= bar)         |       while (*foo++ == bar)
  2053.                 sum += foo;     |               printf ("still a bar\n");
  2054.         else                    |
  2055.                 toosmall++;     |
  2056.  
  2057.         If the body is more complicated than an assignment or function
  2058. call, I put it in braces, even though they really aren't needed, thus:
  2059.  
  2060.         while ((foo = getfoo()) != EOF) |
  2061.         {                               |       for (x=0; x <= 10; x++)
  2062.                 if (foo >= bar)         |       {
  2063.                         sum += foo;     |               for (y=0; y <= 10; y++)
  2064.                 else                    |                       sumxy += x * y;
  2065.                         toosmall++;     |       }
  2066.         }                               |
  2067.  
  2068.         The entire "if-else" or "for" construct is a single statement, but
  2069. intuitively I think about lines and statements being the same (probably a
  2070. holdover from my Fortran days).  If I write a multi-line statement, I put
  2071. braces around it to make that clear (to myself, if nobody else).  Actually,
  2072. in the "for" example above, I would probably drop the braces.  If, however,
  2073. the inner loop needed braces, the outer one would be sure to get them too.
  2074.  
  2075.         A few people have suggested I run my source through a code grinder
  2076. like "cb".  If the output of cb is different from its input, it's a hint I
  2077. goofed somewhere.  Something like "cb < foo.c | diff foo.c -" would do the
  2078. job nicely.  While this is a good idea, I don't see why this isn't built
  2079. into "lint".
  2080.  
  2081.         OK, now can we please start working on somebody else's boo-boos?
  2082. It's embarrassing to see my dirty laundry come back at me 6 times a day,
  2083. even if it is somewhat amusing.
  2084. -- 
  2085. Roy Smith <allegra!phri!roy>
  2086. System Administrator, Public Health Research Institute
  2087. 455 First Avenue, New York, NY 10016
  2088. (Mail) End of article 4893 (of 4956)--what next? [npq] 
  2089.  
  2090. Article 4894 (62 more) in net.lang.c:
  2091. From: jayf@islenet.UUCP (Jay Fields)
  2092. Newsgroups: net.lang.c,net.micro.mac
  2093. Subject: help with sizeof() in HIPPO-C
  2094. Message-ID: <1518@islenet.UUCP>
  2095. Date: 23 Aug 85 04:25:54 GMT
  2096. Date-Received: 28 Aug 85 05:02:27 GMT
  2097. Distribution: net
  2098. Organization: Islenet Inc.,  Honolulu
  2099. Lines: 9
  2100.  
  2101. --MORE--(66%)
  2102. Just discovered that there does not seem to be a sizeof() function
  2103. in Hippo C level I or II.  This would sure be useful for passing
  2104. the number of elements to an array sorting function like
  2105. sort(arrayname,sizeof(array[])/sizeof(array[element0]))
  2106.  
  2107. Thanks in advance for any comments/ideas.
  2108.  
  2109. j fields
  2110. ...!ihnp4!islenet!jayf
  2111. (Mail) End of article 4894 (of 4956)--what next? [npq] 
  2112.  
  2113. Article 4895 (61 more) in net.lang.c:
  2114. From: elric@proper.UUCP (elric)
  2115. Subject: Help
  2116. Message-ID: <248@proper.UUCP>
  2117. Date: 25 Aug 85 01:02:50 GMT
  2118. Date-Received: 28 Aug 85 05:03:20 GMT
  2119. Reply-To: elric@proper.UUCP (Elric of Imrryr)
  2120. Organization: Lunatic Laboratories Unltd.
  2121. Lines: 13
  2122.  
  2123. --MORE--(61%)
  2124.  
  2125.  
  2126.  When ever I attempt to compile the Fahrenheit-Celsius table program (on pg
  2127.  8 of _The C Programming Language_) I
  2128.  get this error:
  2129.         "temp.c", line 8: warning: old-fashioned initialization: use =
  2130.  
  2131. The line of code is:
  2132.                 lower = 0;  /* lower limit of temperature */
  2133.  
  2134.  Could someone tell me what I'm doing wrong?
  2135.     Thanx
  2136.      Elric of Imrryr
  2137. (Mail) End of article 4895 (of 4956)--what next? [npq] 
  2138.  
  2139. Article 4896 (60 more) in net.lang.c:
  2140. From: gwyn@brl-tgr.ARPA (Doug Gwyn <gwyn>)
  2141. Subject: Re: Help
  2142. Message-ID: <965@brl-tgr.ARPA>
  2143. Date: 26 Aug 85 01:55:13 GMT
  2144. Date-Received: 28 Aug 85 05:27:23 GMT
  2145. References: <248@proper.UUCP>
  2146. Organization: Ballistic Research Lab
  2147. Lines: 15
  2148.  
  2149. --MORE--(48%)
  2150. >  When ever I attempt to compile the Fahrenheit-Celsius table program (on pg
  2151. >  8 of _The C Programming Language_) I
  2152. >  get this error:
  2153. >       "temp.c", line 8: warning: old-fashioned initialization: use =
  2154. > The line of code is:
  2155. >               lower = 0;  /* lower limit of temperature */
  2156. >  Could someone tell me what I'm doing wrong?
  2157.  
  2158. No, because you didn't supply enough information.
  2159. The program in the book is okay, so the error must be
  2160. in your code.  Check the line or two above where the
  2161. compiler detects the problem.  Especially check for
  2162. extra/missing { } /* */ ;
  2163. (Mail) End of article 4896 (of 4956)--what next? [npq] 
  2164.  
  2165. Article 4897 (59 more) in net.lang.c:
  2166. From: peters@cubsvax.UUCP (Peter S. Shenkin)
  2167. Newsgroups: net.lang.c,net.unix-wizards
  2168. Subject: Re: how has C bitten you?
  2169. Message-ID: <356@cubsvax.UUCP>
  2170. Date: 26 Aug 85 13:24:49 GMT
  2171. Date-Received: 28 Aug 85 06:35:43 GMT
  2172. References: <302@brl-tgr.ARPA> <471@baylor.UUCP> <148@chinet.UUCP> <>
  2173. Reply-To: peters@cubsvax.UUCP (Peter S. Shenkin)
  2174. Organization: Columbia Univ Biology, New York City
  2175. Lines: 27
  2176. Summary: I've sometimes bitten myself with MACRO definitions... read on!
  2177.  
  2178. --MORE--(43%)
  2179. I've had several bugs involving code hidden in macro definitions which have 
  2180. been very difficult to find.  One I recall offhand went something like this:
  2181.  
  2182. /* OPEN MOUTH *****************************************************************/#define Coords(I)       (complicated.structure.redirection[I].x, \
  2183.                          complicated.structure.redirection[I].y, \
  2184.                          complicated.structure.redirection[I].z   )
  2185. main()
  2186. {
  2187.         ...
  2188.         subr(Coords(i));  /* BITE */
  2189.         ...
  2190. }
  2191. /***************************************************************************/
  2192. subr(x,y,z)
  2193. float x,y,z;
  2194. {...}
  2195. /* SWALLOW ******************************************************************/
  2196.  
  2197. Problem is, when expanded, the call to subr looks like
  2198.         subr((exp1,exp2,exp3));
  2199. The comma operator is applied, and subr() gets only exp1 !!!  The interesting
  2200. thing is that if anyone had asked me, whether (something), ((something)),
  2201. and (((something))) mean the same in C, I would have said "Yes," without
  2202. thinking.  Obviously, I would have been wrong.
  2203.  
  2204. Peter S. Shenkin        philabs!cubsvax!peters          Columbia Univ. Biology
  2205. (Mail) End of article 4897 (of 4956)--what next? [npq] 
  2206.  
  2207.  
  2208. Article 4900 (56 more) in net.lang.c:
  2209. From: DHowell.ES@Xerox.ARPA
  2210. Subject: Re: No Such Thing
  2211. Message-ID: <1008@brl-tgr.ARPA>
  2212. Date: 26 Aug 85 19:59:46 GMT
  2213. Date-Received: 28 Aug 85 06:36:48 GMT
  2214. Sender: news@brl-tgr.ARPA
  2215. Lines: 27
  2216.  
  2217. --MORE--(42%)
  2218. > > ... when it comes to defining one's own
  2219. > > language extensions, this one seems like a winner:
  2220. > > 
  2221. > >     typedef int     bool;
  2222. > >     #define false   0
  2223. > >     #define true    1
  2224. > > 
  2225.  
  2226. > Seems like a loser to me. Just takes up space. I actually have to READ
  2227. it.
  2228.  
  2229. Not really.  You could usually safely assume that if someone is defining
  2230. true and false, he/she is defining it as above.  (if some joker decides
  2231. to define false as 29 and true as 53, he should be forced for eternity
  2232. to covert 10,000-line APL programs to Fortran! :-) )  I think it is much
  2233. easier to read things such as:
  2234.  
  2235.    done _ true;
  2236.  
  2237. than:
  2238.  
  2239.    done _ 1;
  2240.    
  2241. Of course, explanatory comments in any case improves readability even
  2242. more.
  2243.  
  2244. Dan
  2245. (Mail) End of article 4900 (of 4956)--what next? [npq] 
  2246.  
  2247. Article 4901 (55 more) in net.lang.c:
  2248. From: wcs@ho95e.UUCP (x0705)
  2249. Subject: Re: Help
  2250. Message-ID: <184@ho95e.UUCP>
  2251. Date: 26 Aug 85 15:47:33 GMT
  2252. Date-Received: 28 Aug 85 07:09:56 GMT
  2253. References: <248@proper.UUCP> <965@brl-tgr.ARPA>
  2254. Organization: AT&T Bell Labs, Holmdel NJ
  2255. Lines: 30
  2256.  
  2257. --MORE--(26%)
  2258. > >  When ever I attempt to compile the Fahrenheit-Celsius table program (on pg
  2259. > >  8 of _The C Programming Language_) I
  2260. > >  get this error:
  2261. > >     "temp.c", line 8: warning: old-fashioned initialization: use =
  2262. > > 
  2263. > > The line of code is:
  2264. > >             lower = 0;  /* lower limit of temperature */
  2265. > > 
  2266. > >  Could someone tell me what I'm doing wrong?
  2267. > No, because you didn't supply enough information.
  2268. > The program in the book is okay, so the error must be
  2269. > in your code.  Check the line or two above where the
  2270. > compiler detects the problem.  Especially check for
  2271. > extra/missing { } /* */ ;
  2272.  
  2273. The error message you got is normally caused by using constructs that resemble
  2274. some of the "old-fashioned" language constructs.  For example:
  2275.         foo=-40;
  2276. used to mean foo -= 40, instead of foo = (-40).  Several generations of
  2277. compilers since then have code to reject "old-fashioned" constructs, even
  2278. though they're otherwise perfectly legal.
  2279.  
  2280. I this case, I'd check to make sure "lower" has been declared, as a scalar
  2281. (int or double?), and that you don't have any more variable declarations after
  2282. it.  (Since you can't mix decl.'s and executables, the compiler  may be trying
  2283. to get out of a bad situation, and guessing wrong about the error.  Also, as
  2284. Doug suggests, watch for extra/missing delimiters.
  2285. -- 
  2286. ## Bill Stewart, AT&T Bell Labs, Holmdel NJ 1-201-949-0705 ihnp4!ho95c!wcs
  2287. (Mail) End of article 4901 (of 4956)--what next? [npq] 
  2288.  
  2289. Article 4902 (54 more) in net.lang.c:
  2290. From: arnold@gatech.CSNET (Arnold Robbins)
  2291. Subject: Re: Cryptic C (YES/NO vs. TRUE/FALSE + other thoughts)
  2292. Message-ID: <989@gatech.CSNET>
  2293. Date: 23 Aug 85 16:57:20 GMT
  2294. Date-Received: 28 Aug 85 07:59:39 GMT
  2295. References: <2913@ncsu.UUCP>, <709@brl-tgr.ARPA> <5884@utzoo.UUCP>
  2296. Organization: Pr1mebusters!
  2297. Lines: 67
  2298. Summary: some thoughts on coding style for binary symbolic values
  2299.  
  2300. --MORE--(25%)
  2301. In article <5884@utzoo.UUCP>, henry@utzoo.UUCP (Henry Spencer) writes:
  2302. > >     typedef int     bool;
  2303. > >     #define false   0
  2304. > >     #define true    1
  2305. > It's interesting to note that Kernighan&Plauger use "yes" and "no" rather
  2306. > than "true" and "false", and my own reaction is that the code often reads
  2307. > better that way.  Now that's something to *really* start a raging debate
  2308. > about... :-)
  2309. > -- 
  2310. >                               Henry Spencer @ U of Toronto Zoology
  2311.  
  2312. Well, this can get carried too far.  I have worked with code based on
  2313. Software Tools stuff that looks like
  2314.  
  2315.         dowrite (file, YES, NO, NO, YES);
  2316.  
  2317. Now, can you tell what the heck it is doing? Especially when the code for
  2318. dowrite() is 700 lines down in another file? I've often thought that a style
  2319. like
  2320.  
  2321. #define FORCEWRITE      1
  2322. #define NOFORCE         0
  2323.  
  2324. #define APPEND          1
  2325. #define NOAPPEND        0
  2326.  
  2327.         dowrite (file, FORCEWRITE, APPEND, ....);       /* call */
  2328.  
  2329. int dowrite (file, force, append,...)   /* actual procedure */
  2330. ...
  2331. {
  2332.         if (force)
  2333.                 ....
  2334.         if (append)
  2335.                 ....
  2336. }
  2337.  
  2338. is much clearer than the first style.  This is the kind of thing, if anything,
  2339. that "enums" would be most useful for (no flames about how poorly enums are
  2340. implemented. I'm talking conceptually here.).  Overall, TRUE or FALSE or YES
  2341. or NO doesn't make much difference to me.  However, I much prefer the following
  2342.  
  2343.         if (boolean)
  2344.                 something
  2345. and
  2346.  
  2347.         boolean = (x && y || c >= d);
  2348.  
  2349. to the overly verbose
  2350.  
  2351.         if (boolean == TRUE)
  2352.                 something
  2353.  
  2354.         if (x && y || c >= d)
  2355.                 boolean = TRUE;
  2356.         else
  2357.                 boolean = FALSE;
  2358.  
  2359. Now *that* should start a really raging debate! :-)
  2360. -- 
  2361. Arnold Robbins
  2362. CSNET:  arnold@gatech   ARPA:   arnold%gatech.csnet@csnet-relay.arpa
  2363. UUCP:   { akgua, allegra, hplabs, ihnp4, seismo, ut-sally }!gatech!arnold
  2364.  
  2365. Hello. You have reached the Coalition to Eliminate Answering Machines.
  2366. Unfortunately, no one can come to the phone right now....
  2367. (Mail) End of article 4902 (of 4956)--what next? [npq] 
  2368.  
  2369. Article 4903 (53 more) in net.lang.c:
  2370. From: peter@baylor.UUCP (Peter da Silva)
  2371. Subject: Re: Re:  Assignment in Conditionals
  2372. Message-ID: <499@baylor.UUCP>
  2373. Date: 21 Aug 85 16:12:55 GMT
  2374. Date-Received: 28 Aug 85 08:21:36 GMT
  2375. References: <594@brl-tgr.ARPA> <1214@ubc-cs.UUCP>
  2376. Organization: The Power Elite, Houston, TX
  2377. Lines: 21
  2378.  
  2379. --MORE--(36%)
  2380. > A while back, I read a paper from the University of Toronto which
  2381. > tested two otherwise "identical" languages - one was expression
  2382. > oriented and one statement oriented.  Conclusion: the statement
  2383. > oriented one was easier to learn and programming was faster in it.
  2384. > The only problem was that the authors weren't sure how much of
  2385. > this effect was caused by most other programming languages being
  2386. > statement oriented (sorry, I don't have a reference for this -
  2387. > it was a CSRG report from U of T).
  2388.  
  2389. I think I saw that. It was in CACM or some similar journal... just ran
  2390. through my back copies but didn't find it, so either it's not a straight
  2391. article, it has a funny title, or I lent it to someone.
  2392.  
  2393. That wasn't the only flaw. The other problem was that the two languages
  2394. *weren't* otherwise identical, because if they were the statement
  2395. oriented one would have been a subset of the expression oriented
  2396. one.
  2397. -- 
  2398.         Peter (Made in Australia) da Silva
  2399.                 UUCP: ...!shell!neuro1!{hyd-ptd,baylor,datafac}!peter
  2400.                 MCI: PDASILVA; CIS: 70216,1076
  2401. (Mail) End of article 4903 (of 4956)--what next? [npq] 
  2402.  
  2403. Article 4904 (52 more) in net.lang.c:
  2404. From: rlk@chinet.UUCP (Richard L. Klappal)
  2405. Subject: Re: C bites Dog! / project proposal
  2406. Message-ID: <159@chinet.UUCP>
  2407. Date: 27 Aug 85 17:27:52 GMT
  2408. Date-Received: 29 Aug 85 00:32:37 GMT
  2409. References: <872@brl-tgr.ARPA> <2968@sdcc3.UUCP>
  2410. Reply-To: rlk@chinet.UUCP (Richard L. Klappal)
  2411. Organization: chinet, Public Access UN*X, Chicago
  2412. Lines: 43
  2413. Keywords: language proposal
  2414. Summary: 
  2415.  
  2416. --MORE--(27%)
  2417. In article <2968@sdcc3.UUCP> ee161bep@sdcc3.UUCP (Paul Van de Graaf{|stu) writes:
  2418. >I'm ready for something beyond C, and I don't mean C++ or Ada.  If no one
  2419. >obliges all just have to do as Jim says and write my own.
  2420. >
  2421. >Paul van de Graaf      sdcsvax!sdcc3!ee161bep          U. C. San Diego
  2422.  
  2423. I have been feeling similarly.  Have been thinking of trying to write
  2424. something somewhere between C and PL/I.
  2425.  
  2426. 1)      Pointers are pointers, not pointers to ..
  2427.         (Loses pointer arith, has to be array addressing.  Use
  2428.         optimization to reduce common subexpressions to get rid of overhead.
  2429. 2)      More complete output format control.
  2430.         column(n) capability (like F77 Tn, or BASIC TAB(n))
  2431.  
  2432. 3)      string OPERATORS, not function calls.
  2433.  
  2434. 4)      discard ++/-- notation.
  2435.         keep +=, -=, /=, etc
  2436.  
  2437. 5)      then .. else .. end / do .. end / do n=1 to n [by nn] while (..)
  2438.  
  2439. 6)      no assignment in conditionals.
  2440.         means duplicating statements, but less confusion about
  2441.         .. is he assigning, or did he mean ==, and not catch it.
  2442.  
  2443. 7)      switch/case statement (or select ..when)
  2444.  
  2445. 8)      BASED / DEFINED data in stead of unions:  (They sill give me a
  2446.         headache.)
  2447. 10)     conversion functions instead of casts.  They get too unreadable
  2448.         too fast.
  2449.  
  2450. 11)     exception/condition handling ala PL/I.
  2451.  
  2452. 12)     no ternary operator (cond ? true : false)
  2453.  
  2454. 13)     I/O defined in the language. Not added as an afterthought like 
  2455.         Pascal/C/etc.  Will support both stream and record I/O.  Auto
  2456.         indexing (ISAM?/B-TREE?/??)) avail.
  2457. These are the general specs off the top of my head, and will probably
  2458. generate more flames than called for, but I personnaly prefer the
  2459. clarity of PL/I to the terseness of C.
  2460. (Mail) End of article 4904 (of 4956)--what next? [npq] 
  2461.  
  2462. Article 4905 (51 more) in net.lang.c:
  2463. From: chris@umcp-cs.UUCP (Chris Torek)
  2464. Subject: Re: How do I declare...
  2465. Message-ID: <1406@umcp-cs.UUCP>
  2466. Date: 27 Aug 85 10:50:13 GMT
  2467. Date-Received: 29 Aug 85 00:45:45 GMT
  2468. References: <368@persci.UUCP> <159@rtp47.UUCP>
  2469. Organization: U of Maryland, Computer Science Dept., College Park, MD
  2470. Lines: 37
  2471.  
  2472. --MORE--(31%)
  2473. It is interesting to note that recursive type definitions make
  2474. sense only for function pointers, and only because they have side
  2475. effects.  Defining (a pointer to)+ makes no sense, because you can
  2476. never do anything with it.  It only points.  You can do an infinite
  2477. number of indirections and it still just points.
  2478.  
  2479. With function pointers, however, indirecting through them causes
  2480. side effects; one such effect can be "terminate this program",
  2481. which is the magic clause that makes this useful.
  2482.  
  2483. Fascinating.
  2484.  
  2485. By the way, note that structure declarations such as
  2486.  
  2487.         struct foo {
  2488.                 struct foo *next;
  2489.                 ...
  2490.         };
  2491.  
  2492. are not really recursive.  The inner entity is a pointer to struct
  2493. foo, not a struct foo.
  2494.  
  2495. Also by the way, the "most portable" declaration for (function
  2496. returning pointer to)+ is probably
  2497.  
  2498.         <type> *(*(*foo())())()
  2499.  
  2500. as this forces the function to return a pointer to a function that
  2501. returns a pointer; even if pointers to basic types are of different
  2502. sizes, most any compiler will have pointers to "pointer to function
  2503. returning pointer to <type>" being the same size as pointers to
  2504. "pointer to function returning pointer to function returning pointer
  2505. to <type>" and so forth.
  2506. -- 
  2507. In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 4251)
  2508. UUCP:   seismo!umcp-cs!chris
  2509. CSNet:  chris@umcp-cs           ARPA:   chris@maryland
  2510. (Mail) End of article 4905 (of 4956)--what next? [npq] 
  2511.  
  2512. Article 4906 (50 more) in net.lang.c:
  2513. From: throopw@rtp47.UUCP (Wayne Throop)
  2514. Subject: Re: Cryptic C (YES/NO vs. TRUE/FALSE + other thoughts)
  2515. Message-ID: <161@rtp47.UUCP>
  2516. Date: 26 Aug 85 19:26:23 GMT
  2517. Date-Received: 29 Aug 85 01:36:59 GMT
  2518. References: <2913@ncsu.UUCP>, <709@brl-tgr.ARPA> <5884@utzoo.UUCP> <989@gatech.CSNET>
  2519. Organization: Data General, RTP, NC
  2520. Lines: 28
  2521.  
  2522. --MORE--(39%)
  2523. In message 989@gatech, Arnold Robbins gives an interesting example:
  2524.  
  2525. > #define FORCEWRITE    1
  2526. > #define NOFORCE               0
  2527. >
  2528. > #define APPEND                1
  2529. > #define NOAPPEND      0
  2530. >
  2531. >       dowrite (file, FORCEWRITE, APPEND, ....);       /* call */
  2532. >
  2533. > int dowrite (file, force, append,...) /* actual procedure */
  2534.  
  2535. I like this notion in general, but I point out a problem with it that a
  2536. (currently nonexistant) lint-like tool could help with.  What if the
  2537. call was done like so:
  2538.  
  2539.     dowrite( file, NOAPPEND, FORCEWRITE, ... );
  2540.  
  2541. This doesn't do remotely what you intend, and it very hard to detect.
  2542. What you "really want" is to be able to declare two enumerations, and
  2543. make lint check that you don't pass members of one enumeration to a
  2544. formal of another type.
  2545.  
  2546. Also, the "extra checking" that K&R says that lint-like tools are free
  2547. to do with typedefs would be welcome.  No current link (that I am aware
  2548. of) will allow using typedef as a type abstraction device.
  2549. -- 
  2550. Wayne Throop at Data General, RTP, NC
  2551. <the-known-world>!mcnc!rti-sel!rtp47!throopw
  2552. (Mail) End of article 4906 (of 4956)--what next? [npq] 
  2553.  
  2554. Article 4907 (49 more) in net.lang.c:
  2555. From: mab@druca.UUCP (BlandMA)
  2556. Subject: Re: how has C bitten you?
  2557. Message-ID: <956@druca.UUCP>
  2558. Date: 28 Aug 85 19:18:18 GMT
  2559. Date-Received: 30 Aug 85 01:36:24 GMT
  2560. References: <302@brl-tgr.ARPA> <471@baylor.UUCP> <148@chinet.UUCP> <> <356@cubsvax.UUCP>
  2561. Organization: AT&T Information Systems Laboratories, Denver
  2562. Lines: 7
  2563.  
  2564. --MORE--(75%)
  2565. I was amused when I realized why this statement didn't print anything:
  2566.  
  2567.         printf("toggle ">" verbosity\n");
  2568.  
  2569. -- 
  2570. Alan Bland     {ihnp4|allegra}!druca!mab
  2571. AT&T Information Systems, Denver CO
  2572. (Mail) End of article 4907 (of 4956)--what next? [npq] 
  2573.  
  2574. Article 4908 (48 more) in net.lang.c:
  2575. From: rcj@burl.UUCP (Curtis Jackson)
  2576. Newsgroups: net.bugs.usg,net.lang.c,net.unix-wizards
  2577. Subject: SVR2 (at least) printf bug
  2578. Message-ID: <836@burl.UUCP>
  2579. Date: 28 Aug 85 19:42:51 GMT
  2580. Date-Received: 30 Aug 85 01:51:39 GMT
  2581. Reply-To: rcj@burl.UUCP (Curtis Jackson)
  2582. Organization: AT&T Technologies, Burlington NC
  2583. Lines: 40
  2584.  
  2585. --MORE--(27%)
  2586. This bug is known to the Unix Hotline and the appropriate PIC (People
  2587. In Charge), but wasn't known to me so I thought I'd share it.
  2588.  
  2589. If you open a file for simple update (mode "r+" on fopen), then read
  2590. some stuff in the file, then try to write on the file, the writes
  2591. will appear to work perfectly (printf returns good bytecounts and
  2592. everything), but no writes will take place in the real world.
  2593.  
  2594. This happens because the code to check for _IORW (read/write permissions)
  2595. is wrong in printf.c, fprintf.c, vprintf.c, and vfprintf.c.  This
  2596. causes the write permissions (_IOWRT) turnon code to be skipped and
  2597. _doprnt() returns a negative number; so the _cnt field in the FILE
  2598. descriptor decrements rather than increments, and the fflush() therefore
  2599. has no effect -- thus silently no writes.
  2600.  
  2601. The errant lines are:
  2602.  
  2603.         if (!(stdout->_flag | _IOWRT)) {
  2604.                 /* if no write flag */
  2605.                 if (stdout->_flag | _IORW) {
  2606.  
  2607. since |'ing with a constant is not a very good idea, change them to &'s:
  2608.  
  2609.         if (!(stdout->_flag & _IOWRT)) {
  2610.                 /* if no write flag */
  2611.                 if (stdout->_flag & _IORW) {
  2612.  
  2613. and everything works fine.
  2614.  
  2615. I found this bug very interesting to track down since (apparently) the
  2616. initial modes on the file are both _IOWRT and _IORW.  This means that
  2617. if you just write a file fopened with "r+" everything works, but the
  2618. first read turns off _IOWRT and any subsequent writes silently fail.
  2619.  
  2620. Don't forget to remake the library!!
  2621. -- 
  2622.  
  2623. The MAD Programmer -- 919-228-3313 (Cornet 291)
  2624. alias: Curtis Jackson   ...![ ihnp4 ulysses cbosgd mgnetp ]!burl!rcj
  2625.                         ...![ ihnp4 cbosgd akgua masscomp ]!clyde!rcj
  2626. (Mail) End of article 4908 (of 4956)--what next? [npq] 
  2627.  
  2628. Article 4909 (47 more) in net.lang.c:
  2629. From: garys@bunker.UUCP (Gary M. Samuelson)
  2630. Subject: Re: Re: C bites (Null loop-bodies)
  2631. Message-ID: <958@bunker.UUCP>
  2632. Date: 27 Aug 85 15:26:09 GMT
  2633. Date-Received: 30 Aug 85 02:12:01 GMT
  2634. References: <165@3comvax.UUCP> <418@phri.UUCP>
  2635. Distribution: net
  2636. Organization: Bunker Ramo, Trumbull Ct
  2637. Lines: 16
  2638.  
  2639. --MORE--(64%)
  2640. >       I put null loop-bodies on a separate line like in the following
  2641. > example.
  2642. >               while (eatup() != '\n')
  2643. >                       ;
  2644.  
  2645. Putting the semi-colon on a separate line does help make it clear
  2646. that the body of the loop is intentionally null, but what I like
  2647. even better is:
  2648.  
  2649.                 while( eatup() != '\n' )
  2650.                         continue;
  2651.  
  2652. Comments?
  2653.  
  2654. Gary Samuelson
  2655. (Mail) End of article 4909 (of 4956)--what next? [npq] 
  2656.  
  2657. Article 4910 (46 more) in net.lang.c:
  2658. From: joemu@nsc-pdc.UUCP (Joe Mueller)
  2659. Subject: Re: Re: How do I declare...
  2660. Message-ID: <476@nsc-pdc.UUCP>
  2661. Date: 26 Aug 85 23:46:18 GMT
  2662. Date-Received: 30 Aug 85 02:18:21 GMT
  2663. References: <368@persci.UUCP> <159@rtp47.UUCP>
  2664. Organization: NSC Portland Development Center, Portland Oregon
  2665. Lines: 23
  2666.  
  2667. --MORE--(33%)
  2668. > Thus, if you want an array of pointers to arrays of pointers, you can't
  2669. > do it.  Nor can you declare functions returning pointers to functions.
  2670.  
  2671. You have to be kidding, you can declare both of these things although the
  2672. syntax may be a little weird.
  2673.  
  2674. Here's an array of 5 pointers to arrays of 6 pointers to char
  2675.         char *(*foo[5])[6]      /* how do you like that sports fans! */
  2676.  
  2677. Here's a function returning a pointer to a function returning an int
  2678.         int (*foo())()
  2679.  
  2680. If you have trouble declaring things or deciphering existing code, I highly
  2681. recommend a utility called "cdecl". It takes an english description of what
  2682. you want and gives you the C syntax for it, it will also take a C declaration
  2683. and translate it to an english description of what it is. I used it on the
  2684. above examples so I got the declaration right the first time with minimal fuss.
  2685. It has been posted to the net at least once before, if you absolutely can't
  2686. find it elsewhere and you want a copy, I'll send it to you. If too many people
  2687. need it, I'll post it to the net.
  2688.  
  2689. The language has hooks to declare incredibly complex data structures, if your
  2690. compiler can't hack it, it's not the language's fault.
  2691. (Mail) End of article 4910 (of 4956)--what next? [npq] 
  2692.  
  2693. Article 4911 (45 more) in net.lang.c:
  2694. From: reg@vaxine.UUCP (Rick Genter)
  2695. Subject: How to declare a pointer to function returning pointer to function
  2696. Message-ID: <630@vaxine.UUCP>
  2697. Date: 27 Aug 85 13:35:42 GMT
  2698. Date-Received: 30 Aug 85 02:38:39 GMT
  2699. Organization: Automatix, Inc., Billerica, MA
  2700. Lines: 23
  2701.  
  2702. --MORE--(44%)
  2703.  
  2704.      I couldn't resist trying this.  Cdecl claims no problem declaring
  2705. something to be a pointer to a function returning a pointer to a function
  2706. returning int:
  2707.  
  2708. Script started on Tue Aug 27 09:27:43 1985
  2709.  
  2710. % cdecl
  2711. declare x as pointer to function returning pointer to function returning int
  2712. int (*(*x)())()
  2713. %
  2714.  
  2715. Script done on Tue Aug 27 09:28:32 1985
  2716.  
  2717.      No, that's not lisp ... :-)
  2718.  
  2719.                                         - reg
  2720.                                         Rick Genter
  2721.                                         Automatix Inc.
  2722.                                         ...!decvax!encore!vaxine!reg
  2723.  
  2724. (Note: As of next week (9/3/85) I will be at BBN Labs.  I don't know what my
  2725.        new electronic address will be).
  2726. (Mail) End of article 4911 (of 4956)--what next? [npq] 
  2727.  
  2728. Article 4912 (44 more) in net.lang.c:
  2729. From: ben@cernvax.UUCP (ben)
  2730. Subject: Xinu Applications: any experience??
  2731. Message-ID: <217@cernvax.UUCP>
  2732. Date: 27 Aug 85 16:38:14 GMT
  2733. Date-Received: 30 Aug 85 02:47:45 GMT
  2734. Organization: CERN, Geneva/Switzerland
  2735. Lines: 8
  2736.  
  2737. --MORE--(66%)
  2738.  
  2739.   Does anyone out there have experience of making PRACTICAL
  2740. applications using Douglas Comer's Xinu system?  We are
  2741. interested particularly in any real-time applications for
  2742. 68000's.
  2743.  
  2744.    Ben M. Segal,  CERN-DD,  1211 Geneva 23,  Switzerland
  2745.                   (ben@cernvax via mcvax)
  2746. (Mail) End of article 4912 (of 4956)--what next? [npq] 
  2747.  
  2748. Article 4913 (43 more) in net.lang.c:
  2749. From: debe@mit-vax.UUCP (Stephen Humble)
  2750. Subject: Re: Help
  2751. Message-ID: <725@mit-vax.UUCP>
  2752. Date: 28 Aug 85 18:09:48 GMT
  2753. Date-Received: 30 Aug 85 03:44:30 GMT
  2754. References: <248@proper.UUCP>
  2755. Reply-To: debe@mit-vax.UUCP (Stephen Humble)
  2756. Organization: MIT, Cambridge, MA
  2757. Lines: 15
  2758. Summary: hyphen in function name?
  2759.  
  2760. --MORE--(57%)
  2761. Sender:
  2762.  
  2763. [DO THE RIGHT THING]
  2764.  
  2765. >       "temp.c", line 8: warning: old-fashioned initialization: use =
  2766.  
  2767. This has happened to me too, and it's usually because I put a hyphen
  2768. in the function's name, so cc thinks I want to subtract one part of
  2769. the name from the other part, or something equally absurd. Hyphens in
  2770. declarators are a no_no. :-)
  2771. cc is notorious for not telling you that an error has occurred until
  2772. several lines after the actual error.
  2773. (Mail) End of article 4913 (of 4956)--what next? [npq] 
  2774.  
  2775. Article 4914 (42 more) in net.lang.c:
  2776. From: driehuis%hlerul5.BITNET@Berkeley
  2777. Subject: Re: Re: Re: C bites (Null loop-bodies)
  2778. Message-ID: <1066@brl-tgr.ARPA>
  2779. Date: 28 Aug 85 18:22:45 GMT
  2780. Date-Received: 31 Aug 85 02:11:51 GMT
  2781. Sender: news@brl-tgr.ARPA
  2782. Lines: 31
  2783.  
  2784. --MORE--(32%)
  2785. Gary M. Samuelson <garys@bunker.uucp> writes:
  2786. >>     I put null loop-bodies on a separate line like in the following
  2787. >> example.
  2788. >>
  2789. >>         while (eatup() != '\n')
  2790. >>             ;
  2791. >
  2792. >Putting the semi-colon on a separate line does help make it clear
  2793. >that the body of the loop is intentionally null, but what I like
  2794. >even better is:
  2795. >
  2796. >        while( eatup() != '\n' )
  2797. >            continue;
  2798. >
  2799. >Comments?
  2800. Yes. I am not fond of using continue if it is not necessary
  2801. to do so. All loop-modyfying statements require an additional
  2802. effort to read - at least, for me.
  2803. Neither do I like the suggesion I saw in info-c, that read
  2804. something like
  2805. >        while (function() != READY) {
  2806. >             }
  2807. The reason why is quite prosaic: when I edit an existing
  2808. file into something else, with cutting, pasting, and deleting,
  2809. sometimes (no more than once a week :=)) a line or even a
  2810. block of text gets lost, leaving embraced white space.
  2811. My first reaction to seeing braces, embracing nothing, is: oops...
  2812. been too hastily with the delete-line key.
  2813. The convention to use a period on a line by itself is
  2814. sufficient to recognise at first sight: "this is a null
  2815. statement".
  2816. (Mail) End of article 4914 (of 4956)--what next? [npq] 
  2817.  
  2818. Article 4915 (41 more) in net.lang.c:
  2819. From: chris@umcp-cs.UUCP (Chris Torek)
  2820. Subject: Re: Help
  2821. Message-ID: <1420@umcp-cs.UUCP>
  2822. Date: 28 Aug 85 15:16:49 GMT
  2823. Date-Received: 31 Aug 85 02:13:19 GMT
  2824. References: <248@proper.UUCP> <965@brl-tgr.ARPA> <184@ho95e.UUCP>
  2825. Organization: U of Maryland, Computer Science Dept., College Park, MD
  2826. Lines: 36
  2827.  
  2828. --MORE--(34%)
  2829. > > > When ever I attempt to compile the Fahrenheit-Celsius table
  2830. > > > program (on pg 8 of _The C Programming Language_) I get this error:
  2831. > > >   "temp.c", line 8: warning: old-fashioned initialization: use =
  2832.  
  2833. > The error message you got is normally caused by using constructs
  2834. > that resemble some of the "old-fashioned" language constructs.
  2835.  
  2836. Right so far...
  2837.  
  2838. > For example:
  2839. >       foo=-40;
  2840. > used to mean foo -= 40, instead of foo = (-40).
  2841.  
  2842. This is true, but not directly related to the actual error given above.
  2843.  
  2844. > I this case, I'd check to make sure "lower" has been declared, as
  2845. > a scalar (int or double?), and that you don't have any more variable
  2846. > declarations after it.
  2847.  
  2848. The problem is one of two things.  The Portable C Compiler has seen
  2849. either
  2850.  
  2851.         <type> <variable> <constant>
  2852.  
  2853. or
  2854.  
  2855.         <type> <variable> {
  2856.  
  2857. when it gives the "warning: old-fashioned initialization: use ="
  2858. error message.  (The next message may well be "syntax error".)
  2859. One of the rather neat things you can do is run "cc -E" on the
  2860. source file, to see what's actually being compiled.
  2861. -- 
  2862. In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 4251)
  2863. UUCP:   seismo!umcp-cs!chris
  2864. CSNet:  chris@umcp-cs           ARPA:   chris@maryland
  2865. (Mail) End of article 4915 (of 4956)--what next? [npq] 
  2866.  
  2867. Article 4916 (40 more) in net.lang.c:
  2868. From: chris@umcp-cs.UUCP (Chris Torek)
  2869. Subject: Re: How to declare a pointer to function returning pointer to function
  2870. Message-ID: <1421@umcp-cs.UUCP>
  2871. Date: 28 Aug 85 15:19:44 GMT
  2872. Date-Received: 31 Aug 85 02:13:27 GMT
  2873. References: <630@vaxine.UUCP>
  2874. Organization: U of Maryland, Computer Science Dept., College Park, MD
  2875. Lines: 12
  2876.  
  2877. --MORE--(55%)
  2878. > I couldn't resist trying this.  Cdecl claims no problem declaring
  2879. > something to be a pointer to a function returning a pointer to a
  2880. > function returning int:
  2881.  
  2882. There *is* no problem declaring that.  The problem is declaring a
  2883. function returning a pointer to a function returning a pointer to
  2884. a function returning a pointer to a ..., ad infinitum.  *There is
  2885. no base type in the definition*.
  2886. -- 
  2887. In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 4251)
  2888. UUCP:   seismo!umcp-cs!chris
  2889. CSNet:  chris@umcp-cs           ARPA:   chris@maryland
  2890. (Mail) End of article 4916 (of 4956)--what next? [npq] 
  2891.  
  2892. Article 4917 (39 more) in net.lang.c:
  2893. From: arnold@ucsfcgl.UUCP (Ken Arnold%CGL)
  2894. Subject: Re: C bites Dog!
  2895. Message-ID: <625@ucsfcgl.UUCP>
  2896. Date: 28 Aug 85 19:11:11 GMT
  2897. Date-Received: 31 Aug 85 02:40:47 GMT
  2898. References: <872@brl-tgr.ARPA> <2968@sdcc3.UUCP>
  2899. Reply-To: arnold@ucsfcgl.UUCP (Ken Arnold)
  2900. Organization: UCSF Computer Graphics Lab
  2901. Lines: 31
  2902.  
  2903. --MORE--(30%)
  2904. In article <2968@sdcc3.UUCP> ee161bep@sdcc3.UUCP (Paul Van de Graaf) writes:
  2905. >Action also has the if <> then <> fi style bracketing which I suppose was
  2906. >inspired by the Bourne shell.  I personally don't like the case .. esac stuff
  2907. >in the Bourne shell, but I can't understand why C programmers are so concerned
  2908. >about typing 2 to 5 letter keywords instead of (, ), {, and }.  I don't type
  2909. >special characters very well, and I think it's because of having to hit that
  2910. ><shift> key.
  2911.  
  2912. To me it is not a question of typing, but a question of bandwidth.
  2913. Keywords look a lot like variables unless read, whereas symbols don't
  2914. look like variables at all.  The extreme examples are something like
  2915.  
  2916.         add a to b and assign to c
  2917.  
  2918.                 vs.
  2919.  
  2920.         c = a + b
  2921.  
  2922. where the second is clearly more legible.  This can be taken to
  2923. extremes, of course, but I still find that it is easier to scan a
  2924. language which uses a reasonably rich token set instead of a lot of
  2925. keywords.  Once you learn such a set of symbols, it seems easier to
  2926. read quickly, probably because the bandwitdh of communication is
  2927. higher, and operators are quickly visible as operators, as distinct
  2928. from programmer-defined tokens.
  2929.  
  2930. How easy a language is to type seems relatively unimportant compared to
  2931. other factors, including legibility.  APL is reasonably easy to
  2932. *type*...
  2933.  
  2934.                 Ken Arnold
  2935. (Mail) End of article 4917 (of 4956)--what next? [npq] 
  2936.  
  2937. Article 4918 (38 more) in net.lang.c:
  2938. From: scott@othervax.UUCP (Scott Pace)
  2939. Subject: Re: How do I declare...
  2940. Message-ID: <690@othervax.UUCP>
  2941. Date: 27 Aug 85 18:39:58 GMT
  2942. Date-Received: 31 Aug 85 03:38:08 GMT
  2943. References: <368@persci.UUCP> <159@rtp47.UUCP>
  2944. Reply-To: scott@othervax.UUCP (Scott Pace)
  2945. Organization: Philips Information Systems - St. Laurent  P.Q., Canada
  2946. Lines: 49
  2947.  
  2948. --MORE--(34%)
  2949. >> Either I'm missing the perfectly obvious or I've found something
  2950. >> that's impossible to declare in C, even though it makes sense.
  2951.  
  2952. >You have discovered a fundamental flaw in C type notation.  In essence,
  2953. >C allows recursive types only in structs, unions, and enums (and I'm not
  2954. >sure how it would be usefull in enums, so that one can be ruled out for
  2955. >practical purposes).
  2956. >
  2957. >Thus, if you want an array of pointers to arrays of pointers, you can't
  2958. >do it.  Nor can you declare functions returning pointers to functions.
  2959.  
  2960.  
  2961. Well, our compiler seems to handle these sort of constructs ok:-
  2962.  
  2963. looking at an array of pointers to arrays of pointers first...
  2964.  
  2965. int *(*foo1[10])[];
  2966.  
  2967. here foo1 is an array of pointers, each pointer pointing to an array
  2968. of pointers to int's.
  2969. Thus an integer element might be accessed as follows:
  2970.  
  2971. *(*foo1[1])[2] and another way might be **foo1[0]
  2972.  
  2973.  
  2974. now looking at functions returning pointers to functions:-
  2975.  
  2976. int *(*func1())();
  2977.  
  2978. here func is a function returning a pointer to a function, and this
  2979. function returns a pointer to an int.
  2980. Thus you could do things like:
  2981.  
  2982. int *(*func2)(); /*pointer to a function returning a pointer to int*/
  2983. int *x;
  2984. .
  2985. .
  2986. .
  2987. func2 = func1();
  2988. x = (func2)();
  2989. .
  2990. .
  2991. etc.
  2992.  
  2993. Cheers
  2994.  
  2995.         Scott Pace, ...!philabs!micomvax!othervax!scott
  2996.  
  2997. (I hope I got all that right!!!)
  2998. (Mail) End of article 4918 (of 4956)--what next? [npq] 
  2999.  
  3000. Article 4920 (36 more) in net.lang.c:
  3001. From: tim@callan.UUCP (Tim Smith)
  3002. Newsgroups: net.lang.c,net.micro.mac
  3003. Subject: Re: help with sizeof() in HIPPO-C
  3004. Message-ID: <1088@callan.UUCP>
  3005. Date: 27 Aug 85 00:22:46 GMT
  3006. Date-Received: 31 Aug 85 06:00:52 GMT
  3007. References: <1518@islenet.UUCP>
  3008. Distribution: net
  3009. Organization: Callan Data Systems, Westlake Village, CA
  3010. Lines: 27
  3011.  
  3012. --MORE--(41%)
  3013. > Just discovered that there does not seem to be a sizeof() function
  3014. > in Hippo C level I or II.  This would sure be useful for passing
  3015.  
  3016. Level I was written in Pasadena, and when I was bored, I would go over
  3017. and hassle them about things I thought they were doing wrong.  I don't think
  3018. I would have missed a lack of sizeof.  Also, we once ran a set of C progrs
  3019. meant to test out pcc through Hippo level I, and there must have been
  3020. a sizeof in there somewhere!  ( no - I can't tell anyone where to get
  3021. the set of test programs. ).
  3022.  
  3023. Anyway, try all of the following, since I am not sure how they handle
  3024. builtin functions like sizeof -- they may have fucked up the parsing:
  3025.  
  3026.         sizeof x ;              /* where x is a variable */
  3027.         sizeof(x) ;
  3028.         sizeof( x ) ;
  3029.         sizeof (x) ;
  3030.         sizeof ( x ) ;
  3031.         sizeof(int) ;
  3032.         sizeof( int ) ;
  3033.         sizeof (int) ;
  3034.         sizeof ( int ) ;
  3035.  
  3036. If none of these work, give them a call.
  3037. -- 
  3038.                                         Tim Smith
  3039.                                 ihnp4!{cithep,wlbr!callan}!tim
  3040. (Mail) End of article 4920 (of 4956)--what next? [npq] 
  3041.  
  3042.  
  3043. Article 4922 (34 more) in net.lang.c:
  3044. From: franka@mmintl.UUCP (Frank Adams)
  3045. Subject: Re: Cryptic C (YES/NO vs. TRUE/FALSE + other thoughts)
  3046. Message-ID: <625@mmintl.UUCP>
  3047. Date: 27 Aug 85 03:01:24 GMT
  3048. Date-Received: 31 Aug 85 09:52:38 GMT
  3049. References: <2913@ncsu.UUCP> <709@brl-tgr.ARPA> <5884@utzoo.UUCP> <989@gatech.CSNET>
  3050. Reply-To: franka@mmintl.UUCP (Frank Adams)
  3051. Organization: Multimate International, E. Hartford, CT
  3052. Lines: 33
  3053. Summary: Aggregates are even better
  3054.  
  3055. --MORE--(42%)
  3056.  
  3057. In article <989@gatech.CSNET> arnold@gatech.CSNET (Arnold Robbins) writes:
  3058. >
  3059. >Well, this can get carried too far.  I have worked with code based on
  3060. >Software Tools stuff that looks like
  3061. >
  3062. >       dowrite (file, YES, NO, NO, YES);
  3063. >
  3064. >Now, can you tell what the heck it is doing? Especially when the code for
  3065. >dowrite() is 700 lines down in another file? I've often thought that a style
  3066. >like
  3067. >
  3068. >#define FORCEWRITE     1
  3069. >#define NOFORCE                0
  3070. >
  3071. >#define APPEND         1
  3072. >#define NOAPPEND       0
  3073. >
  3074. >       dowrite (file, FORCEWRITE, APPEND, ....);       /* call */
  3075. >
  3076. >
  3077. >is much clearer than the first style.  This is the kind of thing, if anything,
  3078. >that "enums" would be most useful for (no flames about how poorly enums are
  3079. >implemented. I'm talking conceptually here.).
  3080.  
  3081. The problem with your solution is I can just easily write
  3082.  
  3083.         dowrite(file, APPEND, NOFORCE, ...)
  3084.  
  3085. and will have a terrible time finding the error.  This is where Ada wins:
  3086.  
  3087.         dowrite(file, append=>true, force=>false, ...)
  3088.  
  3089. is clear, simple, and error-resistant.
  3090. (Mail) End of article 4922 (of 4956)--what next? [npq] 
  3091.  
  3092. Article 4923 (33 more) in net.lang.c:
  3093. From: stern@bnl.UUCP (eric)
  3094. Subject: Re: VAX VMS C / UNIX C Compatibility -- Need Info
  3095. Message-ID: <150@bnl.UUCP>
  3096. Date: 27 Aug 85 16:50:32 GMT
  3097. Date-Received: 31 Aug 85 09:53:03 GMT
  3098. References: <488@rdin.UUCP> <249@watmum.UUCP> <545@osu-eddie.UUCP>
  3099. Organization: Brookhaven National Lab. Upton, N.Y.
  3100. Lines: 19
  3101.  
  3102. --MORE--(41%)
  3103. > > VMS is very record-ish, while stream i/o is the unix thing. Unfortunately,
  3104. > > port didn't work because we didn't really spend the effort required to do
  3105. > > the QIO's required to fake stream i/o on VMS. 
  3106.  
  3107. A year or two ago, I wrote a xmodem protocol program for VMS and
  3108. UNIX in C.  The effort required to set up the raw state in both OS's
  3109. was equivalent.  Doing these things on VMS takes no more effort
  3110. than finding the appropriate ioctl function codes on UNIX.  When
  3111. it got to doing the reads byte by byte with timeouts, VMS was
  3112. much simpler than UNIX.  Under VMS, just one function call was
  3113. able to read n characters returning an error if more than t
  3114. seconds elapsed between characters.  Under UNIX, it was a complicated
  3115. mess with two functions, alarms, longjmps and extra buffering.
  3116.  
  3117.                                                 Eric G. Stern
  3118.                                                 stern@bnl.arpa
  3119.                                                 stern@bnl.bitnet
  3120.                                                 ...!philabs!sbcs!bnl!stern
  3121. (Mail) End of article 4923 (of 4956)--what next? [npq] 
  3122.  
  3123. Article 4924 (32 more) in net.lang.c:
  3124. From: throopw@rtp47.UUCP (Wayne Throop)
  3125. Subject: Re: How do I declare... (I knew that!)
  3126. Message-ID: <164@rtp47.UUCP>
  3127. Date: 29 Aug 85 17:20:55 GMT
  3128. Date-Received: 2 Sep 85 04:18:33 GMT
  3129. Organization: Data General, RTP, NC
  3130. Lines: 27
  3131.  
  3132. --MORE--(28%)
  3133. I have been inundated with a flood of postings and mail saying "you
  3134. can so declare a pointer to a function returning a pointer to a
  3135. function".  I started replying by mail, but this proves impractical due
  3136. to volume.  Let me introduce my defense as I did in the first letter I
  3137. sent out:
  3138.  
  3139. "Aaaarrrrgggghhhh!"
  3140.  
  3141. There.  I feel better now.  I really *did know* that you can declare
  3142. pointers to arrays of pointers to arrays (of primitive types), and
  3143. pointers to functions returning pointers to functions (returning
  3144. primitive types).  I thought it was clear from the context that I meant
  3145. that it is impossible to declare a pointer to a function returning
  3146. pointer to function *of that function's own type*.  But noooooooo!  All
  3147. you nit-pickers assumed I meant what I said!  Sheeesh!   :-)
  3148.  
  3149. In any event, I still maintain that C's type notation is deficent, in
  3150. that it only allows recursion in declarations of structs, unions, and
  3151. enums (and I haven't found a use for recursion in enums).  It does *not*
  3152. allow recursion in type declaractions that contain only pointer,
  3153. function, or array constructs.
  3154.  
  3155. If you wish to show me the error of my ways, mail or post a typedef F
  3156. of a pointer-to-function-returning-type-F.  My claim is that C allows no
  3157. such constructs, and that this lack is a shortcoming of the C language.
  3158. -- 
  3159. Wayne Throop at Data General, RTP, NC
  3160. <the-known-world>!mcnc!rti-sel!rtp47!throopw
  3161. (Mail) End of article 4924 (of 4956)--what next? [npq] 
  3162.  
  3163. Article 4925 (31 more) in net.lang.c:
  3164. From: stew@harvard.ARPA (Stew Rubenstein)
  3165. Subject: Re: Cryptic C (YES/NO vs. TRUE/FALSE + other thoughts)
  3166. Message-ID: <327@harvard.ARPA>
  3167. Date: 31 Aug 85 02:12:58 GMT
  3168. Date-Received: 2 Sep 85 05:34:43 GMT
  3169. References: <2913@ncsu.UUCP> <709@brl-tgr.ARPA> <5884@utzoo.UUCP> <989@gatech.CSNET> <625@mmintl.UUCP>
  3170. Reply-To: stew@harvard.UUCP (Stew Rubenstein)
  3171. Organization: Aiken Computation Laboratory, Harvard
  3172. Lines: 32
  3173. Summary: 
  3174.  
  3175. --MORE--(36%)
  3176. In article <625@mmintl.UUCP> franka@mmintl.UUCP (Frank Adams) writes:
  3177. >
  3178. >In article <989@gatech.CSNET> arnold@gatech.CSNET (Arnold Robbins) writes:
  3179. >
  3180. >  >Well, this can get carried too far.  I have worked with code based on
  3181. >  >Software Tools stuff that looks like
  3182. >  >
  3183. >  >    dowrite (file, YES, NO, NO, YES);
  3184. >...
  3185. >  >    dowrite (file, FORCEWRITE, APPEND, ....);       /* call */
  3186. >  >
  3187. >  >
  3188. >  >is much clearer than the first style.  This is the kind of thing, if
  3189. >  >anything, that "enums" would be most useful for (no flames about how poorly
  3190. >  >enums are implemented. I'm talking conceptually here.).
  3191. >
  3192. >The problem with your solution is I can just easily write
  3193. >
  3194. >       dowrite(file, APPEND, NOFORCE, ...)
  3195. >
  3196. >and will have a terrible time finding the error.  This is where Ada wins:
  3197. >
  3198. >       dowrite(file, append=>true, force=>false, ...)
  3199.  
  3200. In a perfect world, the argument types for dowrite() would be declared
  3201. as different enum types and the compiler will complain if you mix them
  3202. up (i.e. in new ANSI C if I understand it right).  In a slightly less
  3203. perfect world, lint would complain about the inconsistency.  We were
  3204. talking conceptually, right?  Not to say that the keyword style isn't
  3205. better, but this is one the compiler ought to catch.
  3206.  
  3207. Stew
  3208. (Mail) End of article 4925 (of 4956)--what next? [npq] 
  3209.  
  3210. Article 4926 (30 more) in net.lang.c:
  3211. From: mer@prism.UUCP
  3212. Subject: Re: Re: c programming style - READ THIS
  3213. Message-ID: <5400011@prism.UUCP>
  3214. Date: 28 Aug 85 19:12:00 GMT
  3215. Date-Received: 2 Sep 85 05:36:39 GMT
  3216. References: <90@rtp47.UUCP>
  3217. Lines: 9
  3218.  
  3219. --MORE--(54%)
  3220.  
  3221. Since 'p+n', where p is a pointer and n is an integer, is equivalent to
  3222. adding n*sizeof(whatever p points to), the safe and portable way of adding
  3223. an integer to a pointer treated as an integer is 
  3224.          (char *)p + n
  3225. since (I think) character are always a byte wide.  If that's not always the
  3226. case, I apologize; on the other hand, it's probably safe than converting
  3227. a pointer to an int or a long;  I had trouble porting something from a VAX
  3228. to a Pyramid because of a cast of this sort.
  3229. (Mail) End of article 4926 (of 4956)--what next? [npq] 
  3230.  
  3231. Article 4928 (28 more) in net.lang.c:
  3232. From: darryl@ISM780.UUCP
  3233. Subject: Re: What does the compiler think I am do
  3234. Message-ID: <30000011@ISM780.UUCP>
  3235. Date: 30 Aug 85 12:43:00 GMT
  3236. Date-Received: 2 Sep 85 05:37:23 GMT
  3237. References: <648@ihu1m.UUCP>
  3238. Lines: 15
  3239.  
  3240. --MORE--(46%)
  3241.  
  3242.  
  3243.  
  3244. There is no such thing as an "assignment statement" in C.  Rather, assignment
  3245. is just one more binary operator, and the language supports the "expression
  3246. statement".  What you have written, c - a;, is just another expression
  3247. statement, that merely has no side effects.  According to the Unix philosophy,
  3248. this is perfectly ok, and (if you have a PCC compiler) it probably generates
  3249. the code to load up the values and do the subtract (why? beacause you asked
  3250. it to).  Hence lint.  Lint will also warn you about using = in conditionals
  3251. where you might have meant ==.
  3252.  
  3253.             --Darryl Richman, INTERACTIVE Systems Corp.
  3254.             ...!cca!ima!ism780!darryl
  3255.             The views expressed above are my opinions only.
  3256. (Mail) End of article 4928 (of 4956)--what next? [npq] 
  3257.  
  3258. Article 4929 (27 more) in net.lang.c:
  3259. From: coltoff@burdvax.UUCP ( Joel Coltoff)
  3260. Subject: Re: Re: C bites (Null loop-bodies)
  3261. Message-ID: <2107@burdvax.UUCP>
  3262. Date: 30 Aug 85 14:55:30 GMT
  3263. Date-Received: 2 Sep 85 05:43:25 GMT
  3264. References: <958@bunker.UUCP>
  3265. Organization: System Development Corporation, Paoli PA
  3266. Lines: 10
  3267.  
  3268. --MORE--(73%)
  3269. <<>>
  3270.  
  3271. My approach is to explicitly spell it out with a comment. Sometimes they
  3272. are the only comments in the program
  3273.  
  3274.         while ( eatup() != '\n' )
  3275.                 /* NULL BODY */;
  3276.  
  3277.         - Joel Coltoff
  3278.         {prseby,sdcrdcf,psuvax1}!burdvax!coltoff
  3279. (Mail) End of article 4929 (of 4956)--what next? [npq] 
  3280.  
  3281. Article 4930 (26 more) in net.lang.c:
  3282. From: peter@graffiti.UUCP (Peter da Silva)
  3283. Subject: Re: C bites Dog!
  3284. Message-ID: <131@graffiti.UUCP>
  3285. Date: 30 Aug 85 18:09:30 GMT
  3286. Date-Received: 2 Sep 85 05:44:17 GMT
  3287. References: <872@brl-tgr.ARPA> <1835@reed.UUCP>
  3288. Organization: Information Brokerage Network, Houston, TX
  3289. Lines: 11
  3290.  
  3291. --MORE--(53%)
  3292. > > > > >               if (sv > score);   <----- note extraneous semi-colon
  3293. > > > > >                       score = sv;
  3294. > > > ICK ICK ICK! I hate languages that do that. Ever considered using "cb" as a
  3295. > > > debugging tool? I have an MS-DOS version if anyone wants it...
  3296. > > [...]  What
  3297. > > would you do, compare the output of `cb' with the original? Takes
  3298. > > lots of time & can be visually overlooked.
  3299.  
  3300. Yes. Since I write cb-like code in the first place it's very easy to just
  3301. diff it... any lines diff catches are either long function calls or errors
  3302. of this type.
  3303. (Mail) End of article 4930 (of 4956)--what next? [npq] 
  3304.  
  3305. Article 4931 (25 more) in net.lang.c:
  3306. From: guy@sun.uucp (Guy Harris)
  3307. Newsgroups: net.lang.c,net.unix-wizards
  3308. Subject: Re: Re: how has C bitten you?
  3309. Message-ID: <2737@sun.uucp>
  3310. Date: 31 Aug 85 04:36:43 GMT
  3311. Date-Received: 2 Sep 85 05:47:08 GMT
  3312. References: <302@brl-tgr.ARPA> <471@baylor.UUCP>, <148@chinet.UUCP> <607@bu-cs.UUCP>
  3313. Organization: Sun Microsystems, Inc.
  3314. Lines: 46
  3315.  
  3316. --MORE--(32%)
  3317. > Not really a bite, but I remember when I was first learning C
  3318. > I was quite bewildered by the fact that you couldn't really
  3319. > declare your own 'argv', that is, you couldn't declare an
  3320. > array of pointers to fixed length buffers except perhaps by:
  3321. > char *myargv[] = {
  3322. >       "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0",
  3323. >       "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0",
  3324. >       etc
  3325. > I mean, argv seemed kinda holy to me, disturbing.
  3326.  
  3327. If you want an array of pointers to fixed-length buffers, you can declare it
  3328. as long as the number of such pointers can be determined at the time you
  3329. write the code.
  3330.  
  3331.         char bufs[3][20];
  3332.  
  3333.         char *bufps[3] = {
  3334.                 bufs[0],
  3335.                 bufs[1],
  3336.                 bufs[2],
  3337.         };
  3338.  
  3339. If the number can't be fixed when you write the code, you can set up "bufps"
  3340. at run time.
  3341.  
  3342. Also note that "argv" isn't a pointer to an array of pointers to fixed-length
  3343. buffers, it's a pointer to an array of pointers to strings, which you *can*
  3344. declare.
  3345.  
  3346. > P.S. I know argv is var length, but that would be even harder to declare!
  3347.  
  3348. The secret is that "argv" (or, more correctly, what "argv" points to)
  3349. *isn't* declared.  Pointers need not point to things which have been
  3350. declared; "malloc" returns pointers to objects fabricated on the fly.  If
  3351. you have "n" arguments ("n" is a variable here), just do
  3352.  
  3353.         register char **argv;
  3354.  
  3355.         argv = (char **)malloc(n * sizeof(char *));
  3356.  
  3357. And you can fill them in.
  3358.  
  3359.         Guy Harris
  3360. (Mail) End of article 4931 (of 4956)--what next? [npq] 
  3361.  
  3362. Article 4932 (24 more) in net.lang.c:
  3363. From: doug@terak.UUCP (Doug Pardee)
  3364. Subject: Re: Order of evaluation
  3365. Message-ID: <692@terak.UUCP>
  3366. Date: 30 Aug 85 18:01:29 GMT
  3367. Date-Received: 2 Sep 85 06:13:44 GMT
  3368. References: <764@dataio.UUCP>
  3369. Organization: Calcomp Display Products Division, Scottsdale, AZ, USA
  3370. Lines: 17
  3371.  
  3372. --MORE--(41%)
  3373. > >OK, I understand that order of evaluation is not guaranteed.  I assume that
  3374. > >was done to make compilers easier to write.  Is there any other reason?  Does> >it really make compilers easier to write?
  3375. > Also, allowing the compiler to reorder the expression within certain
  3376. > limits allows it to do some optimizations. Most code is not affected by
  3377. > order of evaluation, and C does allow an order to be forced (by assigning
  3378. > an explicit temporary), so I think this is very reasonable.
  3379.  
  3380. What drives me up a wall is that C does *not* allow an order to be
  3381. forced by using parentheses!  The compiler is at liberty to ignore
  3382. parens which group operators of the same precedence.  <e.g. a+(b+c)>
  3383.  
  3384. I don't think much of the notion of having to store intermediate results
  3385. just to get the correct answer.
  3386. -- 
  3387. Doug Pardee -- CalComp -- {seismo!noao,decvax!noao,ihnp4}!terak!doug
  3388. (Mail) End of article 4932 (of 4956)--what next? [npq] 
  3389.  
  3390. Article 4933 (23 more) in net.lang.c:
  3391. From: nazgul@apollo.uucp (Kee Hinckley)
  3392. Subject: Wanted: Info on C Interpreters
  3393. Message-ID: <289ebe40.8e4@apollo.uucp>
  3394. Date: 29 Aug 85 17:45:43 GMT
  3395. Date-Received: 2 Sep 85 06:22:21 GMT
  3396. Organization: Apollo Computer, Chelmsford, Mass.
  3397. Lines: 23
  3398.  
  3399. --MORE--(37%)
  3400. <now you c me now you don't>
  3401.  
  3402. I'm looking for any information anyone can give me on C interpreters,
  3403. primarily ones that run on Unix, but info on others is welcome.  In
  3404. particular I'd like to know:
  3405.  
  3406.     Who makes it?
  3407.     What is it written in?
  3408.     How does it work (pcode, trees...)?
  3409.     How good is it?
  3410.     And of course...  How much does it cost?
  3411.     And anything else you'd like to add.
  3412.  
  3413.  
  3414.                                             Kee Hinckley
  3415.                                             (617) 256-6600
  3416.                                             ...decvax!wanginst!apollo!nazgul
  3417.  
  3418.                                 
  3419. The views expressed herein are not necessarily those of Apollo Computer, since
  3420. views are naturally expressed in a block structured environment.  Apollo forms
  3421. the containing block in which I reside, but the views expressed herein are all
  3422. in local variables that temporarily override any views help by Apollo Computer.
  3423. (Mail) End of article 4933 (of 4956)--what next? [npq] 
  3424.  
  3425. Article 4934 (22 more) in net.lang.c:
  3426. From: cottrell@nbs-vms.ARPA (COTTRELL, JAMES)
  3427. Subject: This Sentence is False
  3428. Message-ID: <1118@brl-tgr.ARPA>
  3429. Date: 30 Aug 85 01:20:41 GMT
  3430. Date-Received: 2 Sep 85 06:25:09 GMT
  3431. Sender: news@brl-tgr.ARPA
  3432. Lines: 97
  3433.  
  3434. --MORE--(12%)
  3435. /* Fiercely I go into battle:
  3436. > I have always thought that to be a machine dependancy (the value of true and
  3437. > false).  Maybe I'm wrong.  But, different machines DO have different ideas
  3438. > of which is true and false (at the assembler level).  And it is simply
  3439. > a convention.
  3440.  
  3441. Machines have no concept of truth. They can determine if a condition
  3442. (equality, greater than, negative, overflow, etc.) exists and then
  3443. *dynamically* alter the course of their control flow. But no machine
  3444. I know of has a `branch if true' instruxion. Note I am not talking
  3445. about the abstraxion a la 68k where an unconditional branch is named
  3446. `branch if true' & the converse is called `branch if false'. I am 
  3447. talking about a *conditional* `branch if true'.
  3448.  
  3449. > Still though, #define TRUE (1==1) is very obvious, to the point, correct,
  3450. > proper, and all sorts of things.  And it doesn't require one to know
  3451. > that detail about C that the convention is ~0 == TRUE and 0 == FALSE.
  3452.  
  3453. Your attention span must be even shorter than mine. (What were we talking
  3454. about :-) If you are consistant, ignorance is bliss. But what about
  3455. fred's code over there, if (p). Hmmmm, now what does that do?
  3456.  
  3457. > But C gives you all these operators which allow you to define things
  3458. > machine independantly rather than hardcoding values.  Obviously I mean
  3459. > casts and the sizeof operator.  Also arithmetic to pointers.  So why not
  3460. > TRUE and FALSE?
  3461. > --- David Herron
  3462.  
  3463. Because who needs them? Integers do quit well, thank you.
  3464. On to my next victim.
  3465.  
  3466. > Not really.  You could usually safely assume that if someone is defining
  3467. > true and false, he/she is defining it as above.  (if some joker decides
  3468. > to define false as 29 and true as 53, he should be forced for eternity
  3469. > to covert 10,000-line APL programs to Fortran! :-) )
  3470.  
  3471. Agreed. But it's not 29 & 53 were talking about now is it? Zero & One
  3472. have certain useful mathematical properties, described below.
  3473.  
  3474. > I think it is much easier to read things such as:
  3475. >
  3476. >    done = true;
  3477. > than:
  3478. >    done = 1;
  3479.  
  3480. How about `done++'. Most variables are initialized to false. It's
  3481. kinda like reality, nothing can be taken for granted (default false)
  3482. unless it appears to be true.
  3483.  
  3484. > Of course, explanatory comments in any case improves readability even
  3485. > more.
  3486. > Dan Howell
  3487.  
  3488. Most definitely. Now for the last one:
  3489.  
  3490. > To me, the mapping TRUE -> 0 and FALSE -> non-zero doesn't seem obvious,
  3491. > and I'm sure it isn't to most programmers who ever worked in assembler.
  3492. > In assembler, one often writes the following (I'm using pseudocode
  3493. > rather than any particular assembler):
  3494. >       compare two values
  3495. >       jumpto stuff  if zero
  3496. > Which is the assembler equivalent of
  3497. >         if (value1 == value2)
  3498. >         <do stuff> ;
  3499.  
  3500. I think you've got it backwards. 
  3501.  
  3502. > When I was in high school I was programming TRS-80's in both assembler
  3503. > and BASIC, and I had lots of trouble remembering whether BASIC
  3504. > represented truth as zero or -1.  No such memory is needed for the
  3505. > assembler, of course, since comparison is merely done by subtraction (a
  3506. > compare instruction is usually just a subtract instruction that doesn't
  3507. > store the result anywhere), so it is obvious what the zero indicator
  3508. > means.  It is not so obvious to me that in C 0 should mean false and 1
  3509. > mean true.
  3510. > -- 
  3511. >     Barry Margolin
  3512. >     ARPA: barmar@MIT-Multics
  3513. >     UUCP: ..!genrad!mit-eddie!barmar
  3514.  
  3515. Ah but it is! Consider the mathematical implications of it! The MAX
  3516. funxion is just the expression `(A > B) * A + (A < B) * B'. APL, which
  3517. was designed by a mathematician, uses the exact same concept. The
  3518. idea of `P implies Q' can be written as `P <= Q'! There have been many
  3519. different *conventions* used in many languages to represent the
  3520. *hidden* boolean values, sometimes differing between implementations.
  3521. I think time will show that APL & C do it the best way. At least the
  3522. cat's out of the bag & everybody knows what the spots look like.
  3523.  
  3524.         jim             cottrell@nbs
  3525. */
  3526. ------
  3527. (Mail) End of article 4934 (of 4956)--what next? [npq] 
  3528.  
  3529. Article 4935 (21 more) in net.lang.c:
  3530. From: cottrell@nbs-vms.ARPA (COTTRELL, JAMES)
  3531. Subject: I Do Declare!
  3532. Message-ID: <1113@brl-tgr.ARPA>
  3533. Date: 29 Aug 85 22:09:59 GMT
  3534. Date-Received: 2 Sep 85 06:51:46 GMT
  3535. Sender: news@brl-tgr.ARPA
  3536. Lines: 41
  3537.  
  3538. --MORE--(29%)
  3539. /*
  3540. In article <368@persci.UUCP> roman@persci.UUCP writes:
  3541. > Either I'm missing the perfectly obvious or I've found something
  3542. > that's impossible to declare in C, even though it makes sense.  I'm
  3543. > trying to implement a simple finite state machine with states
  3544. > represented by C functions.  Each state function would accept some
  3545. > input value as an argument and return a pointer to the function
  3546. > implementing the next state...
  3547.  
  3548. Cheat! Declare your variable as a pointer to funxion returning int
  3549. (or char (or void) pointer for sticklers) and then use casts.
  3550. Saves a lot of headaches trying to figure out all those types.
  3551. With char or void pointers, there ought to be a portable way.
  3552.  
  3553. typedef int      (*PFI)();
  3554. typedef char    *(*PFCP)();     /* for portability sticklers */
  3555. typedef void    *(*PFVP)();     /* if available */
  3556.  
  3557. int     other();
  3558. int     init();                 /* initial func */
  3559. PFI     state = init;           /* state var */
  3560.  
  3561. init(arg)
  3562. {
  3563.         state = other;          /* no problem to set directly */
  3564.         ...
  3565.         return((int)state);     /* to return we must cast */
  3566.         ...
  3567.         state = (PFI)other(arg);/* must cast to assign */
  3568.         ...
  3569.         (*state)(arg);          /* can be called directly */
  3570.         ...
  3571.         while (state = (PFI)(*state)(arg));     /* until no more funx */
  3572. }
  3573.  
  3574. Once in a while you get shown the light
  3575. In the strangest of places if you look at it right.
  3576.  
  3577.         jim             cottrell@nbs
  3578. */
  3579. ------
  3580. (Mail) End of article 4935 (of 4956)--what next? [npq] 
  3581.  
  3582. Article 4936 (20 more) in net.lang.c:
  3583. From: gwyn@brl-tgr.ARPA (Doug Gwyn <gwyn>)
  3584. Subject: Re: C bites Dog! / project proposal
  3585. Message-ID: <1101@brl-tgr.ARPA>
  3586. Date: 29 Aug 85 18:48:51 GMT
  3587. Date-Received: 2 Sep 85 06:56:25 GMT
  3588. References: <872@brl-tgr.ARPA> <2968@sdcc3.UUCP> <159@chinet.UUCP>
  3589. Organization: Ballistic Research Lab
  3590. Lines: 9
  3591.  
  3592. --MORE--(60%)
  3593. Judging by rlk's language proposal, he doesn't like those things
  3594. that C lovers think are C's greatest advantages.  He is certainly
  3595. entitled to his opinion (and his own language), so I hope we can
  3596. avoid zillions of return flames on this.
  3597.  
  3598. > ... but I personnaly prefer the clarity of PL/I to the terseness of C.
  3599.  
  3600. Besides, what can one say to a person who thinks PL/I is
  3601. distinguished by its clarity?
  3602. (Mail) End of article 4936 (of 4956)--what next? [npq] 
  3603.  
  3604.  
  3605. Article 4938 (18 more) in net.lang.c:
  3606. From: cottrell@nbs-vms.ARPA (COTTRELL, JAMES)
  3607. Subject: Array Declarations
  3608. Message-ID: <1106@brl-tgr.ARPA>
  3609. Date: 29 Aug 85 19:07:54 GMT
  3610. Date-Received: 2 Sep 85 06:57:00 GMT
  3611. Sender: news@brl-tgr.ARPA
  3612. Lines: 1
  3613.  
  3614. --MORE--(98%)
  3615. ------
  3616. (Mail) End of article 4938 (of 4956)--what next? [npq] 
  3617.  
  3618. Article 4939 (17 more) in net.lang.c:
  3619. From: cottrell@nbs-vms.ARPA (COTTRELL, JAMES)
  3620. Subject: Array Declarations
  3621. Message-ID: <1110@brl-tgr.ARPA>
  3622. Date: 29 Aug 85 20:04:51 GMT
  3623. Date-Received: 2 Sep 85 06:59:11 GMT
  3624. Sender: news@brl-tgr.ARPA
  3625. Lines: 42
  3626.  
  3627. --MORE--(25%)
  3628. /*
  3629. > Not really a bite, but I remember when I was first learning C
  3630. > I was quite bewildered by the fact that you couldn't really
  3631. > declare your own 'argv', that is, you couldn't declare an
  3632. > array of pointers to fixed length buffers except perhaps by:
  3633. > char *myargv[] = {
  3634. >       "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0",
  3635. >       "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0",
  3636. > I mean, argv seemed kinda holy to me, disturbing.
  3637. >       -Barry Shein, Boston University
  3638. > P.S. I know argv is var length, but that would be even harder to declare!
  3639.  
  3640. Yeah. C will only create hidden literals of type char array. Wouldn't it
  3641. be nice to use expressions like `intptr = &2;' instead of the more
  3642. readable & nonportable `intptr = "\2\0\0\0";' (VAX) :-) Seriously tho,
  3643. remember DEC Fortran's `vectored arrays'? Why not get rid of `real'
  3644. arrays as well, & make them all pointers. When we declare: 
  3645.  
  3646.                 int     array[3][5];
  3647.  
  3648. let's really let the compiler do:
  3649.  
  3650.                 int     ??[15];
  3651.                 int     *?[3] = { ?? + 0, ?? + 5, ?? + 10};
  3652.                 int     **array = ?;
  3653.  
  3654. where `?' & `??' are invisible `names' known only to the compiler.
  3655. Forgive me if I got the subscripts backwards. This would lose for one
  3656. dimensional arrays & constant references to multidimensional arrays, but
  3657. gain speed on random refs to multiple arrays. The extra space is the
  3658. price one pays for consistancy. Or maybe only higher dimension arrays
  3659. should be vectored. To gain vectoring one would tack on `[1]' to an
  3660. array name or use the (nonexistent) keyword `vectored'. Or maybe nobody
  3661. cares. Just idle thoughts.
  3662.  
  3663.         jim             cottrell@nbs
  3664. */
  3665. ------
  3666. (Mail) End of article 4939 (of 4956)--what next? [npq] 
  3667.  
  3668. Article 4940 (16 more) in net.lang.c:
  3669. From: cottrell@nbs-vms.ARPA (COTTRELL, JAMES)
  3670. Subject: No Such Thing
  3671. Message-ID: <1112@brl-tgr.ARPA>
  3672. Date: 29 Aug 85 20:48:56 GMT
  3673. Date-Received: 2 Sep 85 06:59:23 GMT
  3674. Sender: news@brl-tgr.ARPA
  3675. Lines: 124
  3676.  
  3677. --MORE--(9%)
  3678. /*
  3679. > From: Mike (I'll be mellow when I'm dead) Meyer <mwm@ucbopal.CC>
  3680.  
  3681. That's MY slogan too.
  3682.  
  3683. > In 868@brl-tgr.ARPA jim cottrell (cottrell@nbs-vms.ARPA) says:
  3684. > > Flame On! THERE IS NO SUCH THING AS A BOOLEAN!!! Flame Off.
  3685. > :-) Ok, we now know that jim doesn't believe in true and false. Does
  3686. > he drop right and wrong at the same time? How about write and read? :-)
  3687.  
  3688. Cute.
  3689.  
  3690. > > In case you hadn't noticed, `<' & company are infix operator that
  3691. > > return a constant `zero' or `one'. Thus, *every* conditional using
  3692. > > the `boolean' operators ultimately reduces to either
  3693. > >     if (0) { ... }          or      if (1) { ... }
  3694. > > THIS IS NOT A KLUDGE! It is the WAY IT SHOULD BE! What could be
  3695. > > more mnemonic (except to a nihilist :-) than TRUE if nonzero, and
  3696. > > FALSE if zero. One of C's design virtues is that it is minimal, yet
  3697. > > (relatively) complete. Don't drag outmoded concepts into the future!
  3698. > TRUE if nonzero, FALSE if zero? Sounds like jim just built a map from
  3699. > the set of C integers to booleans. But booleans don't exist, so such a
  3700. > map can't exist. Maybe what jim meant was:
  3701. >       if (expression) { ... }
  3702. > is the same as:
  3703. >       if expression is non-zero then { ... }.
  3704.  
  3705. That's what the book says.
  3706.  
  3707. > BTW, for something more mnemonic that
  3708. >       0 -> FALSE, {x | x /= 0} -> TRUE,
  3709. > how about
  3710. >       nil -> FALSE, {x | x /= nil} -> TRUE, or
  3711. >       {x | x = 0 mod 2} -> TRUE, {x | x = 1 mod 2} -> FALSE?
  3712.  
  3713. As for the first, sounds like LISP. Are you proposing a funny predefined
  3714. `thing' called `nil' that points to itself like in LISP? Will we have
  3715. to cast all our tests to the proper type?
  3716.  
  3717. As for the first, sounds like VAX Fortran. Since the VAX is 
  3718. little-endian, the low bit test words on all LOGICAL*[124] types. 
  3719.  
  3720. There have been all sorts of true-false mappings & conventions. Let's
  3721. not forget using the sign bit. Anyway, to my mind, (& evidently to
  3722. K&R) the use of zero to represent false is the most reasonable
  3723. thing to do, if restricted to *in-band* values. When you ain't
  3724. got nothin', you got nothin' to lose.
  3725.  
  3726. > Second BTW: C is not minimal. It's not bad, but there a half-dozen or
  3727. > so languages that have fewer operators, and equivalent completeness.
  3728. > Most of those are harder to use than C, though.
  3729.  
  3730. Okay. What I mean by minimal is that it includes only those features
  3731. truly necessary to fully describe an idealized portable machine and 
  3732. which have meaning to the compiler. There is no exponentiation because
  3733. few (if any) machines have it as a primitive. There is no repeat-until
  3734. statement because that is a trivial variation of a while. There is no
  3735. I/O, sets, booleans, complex numbers, or inline functions (except 
  3736. sizeof) that most other general purpose languages have.
  3737.  
  3738. > > > Many Boolean expressions are not best thought of as comparison of
  3739. > > > an arithmetic quantity against zero.  For example:
  3740. > > >   while ( ! Done() )
  3741. > > >           Perform_Action();
  3742. > > 
  3743. > > We agree, but for different reasons. You insist on dragging in
  3744. > > an outmoded concept, then complaining that it doesn't fit very well.
  3745. > > I just read what it says.
  3746. > Sorry, but you've got it backwards. He's trying to pull a modern
  3747. > concept (TRUTH :-) into an obsolete language. Of course, if your
  3748. > language is nothing more than a high-level assembler, then using the
  3749. > funny "zero is false" map is ok, providing the underlying hardware
  3750. > doesn't provide a boolean type of it's own.
  3751.  
  3752. Like What? Zero is the most unique & important constant in the universe!
  3753. All (or 99.99%) machines have a branch on (non)zero & some even have
  3754. clear instruxions. 
  3755.  
  3756. > > > I am pretty conservative
  3757. > > 
  3758. > > I think this pretty much sums it up.
  3759. > Yeah - somebody who expects the programming languages to make their
  3760. > job easier is pretty conservative. I'm that way to - I want a language
  3761. > that makes it easy to turn my thoughts into code. This is why I prefer
  3762. > ALGOLW or C to FORTRAN or BASIC, and CLU or LISP to ALGOLW or C.
  3763.  
  3764. Why do you keep putting a `W' on the end of `ALGOL'? I haven't a CLU :-)
  3765.  
  3766. > > Actually, Doug, I'm not so much writing this to you as much as
  3767. > > all those other people out there who insist on fortrash as a model
  3768. > > for all their computing. Sorry about the cheap shot, but I wish you
  3769. > > were a little more daring in your philosophy. K & R were.
  3770. > Sorry, but I can't resist: Jim, from where I stand, *you* insist on
  3771. > fortrash as a model for your computing. There are more similarities
  3772. > between C and fortrash than differences. The C "if x is zero then ..."
  3773. > reminds me of the fortrash arithmetic if. But further discussion
  3774. > belongs in net.lang.*
  3775.  
  3776. Twisting things around a bit aren't we? I never even used the
  3777. arithmatic if except when I was a freshman & thought it was cute.
  3778. There are two main features of a language as I see it: 1) control
  3779. struxures, & 2) data struxures. Fortran 77 has matured somewhat in
  3780. the former, but leaves a lot to be desired in the latter.
  3781.  
  3782. >       <mike
  3783. > "Truth is variable."
  3784. > * disclaimer: I like C. It's easily the best language to come out of
  3785. > the early '70s I've seen. However, this does not imply that 1) it's
  3786. > perfect; or 2) there aren't better general purpose languages
  3787. > available.
  3788.  
  3789. 1) Agreed. I have criticized C as well in this very forum.
  3790. 2) Maybe so. But *widely* available?
  3791.  
  3792.         jim             cottrell@nbs
  3793. */
  3794. ------
  3795. (Mail) End of article 4940 (of 4956)--what next? [npq] 
  3796.  
  3797. Article 4941 (15 more) in net.lang.c:
  3798. From: cottrell@nbs-vms.ARPA (COTTRELL, JAMES)
  3799. Subject: No Such Thing
  3800. Message-ID: <1116@brl-tgr.ARPA>
  3801. Date: 29 Aug 85 23:56:53 GMT
  3802. Date-Received: 2 Sep 85 07:03:41 GMT
  3803. Sender: news@brl-tgr.ARPA
  3804. Lines: 11
  3805.  
  3806. --MORE--(64%)
  3807. /*
  3808. > I don't understand the point of explaining how C maps
  3809. > natural booleans into arithmetic terms; that is just
  3810. > what I am complaining about.
  3811.  
  3812. Does anyone else besides Gwyn have trouble with mapping booleans to integers?
  3813. (Sorry Doug, I just couldn't resist :-)
  3814.  
  3815.         jim             cottrell@nbs
  3816. */
  3817. ------
  3818. (Mail) End of article 4941 (of 4956)--what next? [npq] 
  3819.  
  3820. Article 4942 (14 more) in net.lang.c:
  3821. From: Purtill@MIT-MULTICS.ARPA (Mark Purtill)
  3822. Subject: Re(n): null loop bodies
  3823. Message-ID: <1117@brl-tgr.ARPA>
  3824. Date: 30 Aug 85 00:12:41 GMT
  3825. Date-Received: 2 Sep 85 07:03:58 GMT
  3826. Sender: news@brl-tgr.ARPA
  3827. Lines: 17
  3828.  
  3829. --MORE--(61%)
  3830. <Fnord>
  3831. I use either:
  3832.  
  3833.           while (test ) ; /* no body! */
  3834.  
  3835. or
  3836.           
  3837.           while (test ) {
  3838.                     ;
  3839.                     }
  3840.  
  3841. depending on space (on the screen) considerations.  Or at least I ought
  3842. to.
  3843.  
  3844.        Mark
  3845. ^.-.^  Purtill at MIT-MULTICS.ARPA    **Insert favorite disclaimer here**
  3846. (("))  2-032 MIT Cambrige MA 02139
  3847. (Mail) End of article 4942 (of 4956)--what next? [npq] 
  3848.  
  3849. Article 4943 (13 more) in net.lang.c:
  3850. From: bc@cyb-eng.UUCP (Bill Crews)
  3851. Subject: Re: "handy.h"
  3852. Message-ID: <685@cyb-eng.UUCP>
  3853. Date: 30 Aug 85 15:02:54 GMT
  3854. Date-Received: 2 Sep 85 07:19:58 GMT
  3855. References: <10200006@ada-uts.UUCP>
  3856. Organization: Cyb Systems, Austin, TX
  3857. Lines: 17
  3858.  
  3859. --MORE--(50%)
  3860. > I'm interested in coming up with an include file, say "handy.h",
  3861. >
  3862. > -- Rich Wagner
  3863.  
  3864. If people, when choosing names for functions, variables, files, etc, would
  3865. think at least briefly about what name would be the most meaningful to an
  3866. uninitiated reader, we readers would have a much easier time.  I would
  3867. suggest you come up with names like types.h or ctlchars.h or whatever,
  3868. segregate them functionally and name them appropriately.
  3869.  
  3870. -- 
  3871.   /  \    Bill Crews
  3872.  ( bc )   Cyb Systems, Inc
  3873.   \__/    Austin, Texas
  3874.  
  3875. [ gatech | ihnp4 | nbires | seismo | ucbvax ] ! ut-sally ! cyb-eng ! bc
  3876. (Mail) End of article 4943 (of 4956)--what next? [npq] 
  3877.  
  3878. Article 4944 (12 more) in net.lang.c:
  3879. From: jeff@isi-vaxa (Jeffery A. Cavallaro)
  3880. Subject: Re: \"handy.h\"
  3881. Message-ID: <1133@brl-tgr.ARPA>
  3882. Date: 30 Aug 85 16:48:17 GMT
  3883. Date-Received: 2 Sep 85 07:20:52 GMT
  3884. Sender: news@brl-tgr.ARPA
  3885. Lines: 12
  3886.  
  3887. --MORE--(53%)
  3888. Well, for starters you should take a look at the specification for the
  3889. portability definition file "stdtype.h" described in the PLUM HALL
  3890. document "C PROGRAMMING STANDARDS AND GUIDELINES".  The latest version I
  3891. have is JAN-1982, edition 3.  In this addition, stdtype is described in
  3892. section 1.3.  Every site should have a version for each particular
  3893. machine type.
  3894.  
  3895. In addition, I would suggest the following:
  3896.  
  3897. #define         FALSE           0
  3898. #define         TRUE            1
  3899. #define         EOL             '\0'            /* End-of-line */
  3900. (Mail) End of article 4944 (of 4956)--what next? [npq] 
  3901.  
  3902. Article 4945 (11 more) in net.lang.c:
  3903. From: jeff@isi-vaxa.ARPA (Jeffery A. Cavallaro)
  3904. Subject: Re: \"handy.h\"
  3905. Message-ID: <1135@brl-tgr.ARPA>
  3906. Date: 30 Aug 85 17:29:54 GMT
  3907. Date-Received: 2 Sep 85 07:21:07 GMT
  3908. Sender: news@brl-tgr.ARPA
  3909. Lines: 12
  3910.  
  3911. --MORE--(53%)
  3912. Well, for starters you should take a look at the specification for the
  3913. portability definition file "stdtype.h" described in the PLUM HALL
  3914. document "C PROGRAMMING STANDARDS AND GUIDELINES".  The latest version I
  3915. have is JAN-1982, edition 3.  In this addition, stdtype is described in
  3916. section 1.3.  Every site should have a version for each particular
  3917. machine type.
  3918.  
  3919. In addition, I would suggest the following:
  3920.  
  3921. #define         FALSE           0
  3922. #define         TRUE            1
  3923. #define         EOL             '\0'            /* End-of-line */
  3924. (Mail) End of article 4945 (of 4956)--what next? [npq] 
  3925.  
  3926. Article 4946 (10 more) in net.lang.c:
  3927. From: weltyrp@rpics.UUCP (Richard Welty)
  3928. Subject: Re: Re: Re: C bites (Null loop-bodies)
  3929. Message-ID: <176@rpics.UUCP>
  3930. Date: 31 Aug 85 00:18:52 GMT
  3931. Date-Received: 2 Sep 85 08:18:51 GMT
  3932. References: <165@3comvax.UUCP> <418@phri.UUCP> <958@bunker.UUCP>
  3933. Distribution: net
  3934. Organization: RPI CS Department, Troy  NY
  3935. Lines: 37
  3936.  
  3937. --MORE--(42%)
  3938. > >     I put null loop-bodies on a separate line like in the following
  3939. > > example.
  3940. > > 
  3941. > >             while (eatup() != '\n')
  3942. > >                     ;
  3943. > Putting the semi-colon on a separate line does help make it clear
  3944. > that the body of the loop is intentionally null, but what I like
  3945. > even better is:
  3946. >               while( eatup() != '\n' )
  3947. >                       continue;
  3948. I personally like to use {} in all cases ... thus:
  3949.  
  3950.         while( eatup() != '\n'){}
  3951. or
  3952.         while( eatup() != '\n')
  3953.             {}
  3954. or even
  3955.         while( eatup() != '\n')
  3956.         {
  3957.         }
  3958. By using the {} all the time, even for null cases, I insure
  3959. that things like
  3960.         if( cond);
  3961. don't happen ...
  3962. -- 
  3963.                                 Rich Welty
  3964.  
  3965.         (I am both a part-time grad student at RPI and a full-time
  3966.          employee of a local CAE firm, and opinions expressed herein
  3967.          have nothing to do with anything at all)
  3968.  
  3969.         CSNet:   weltyrp@rpi
  3970.         ArpaNet: weltyrp.rpi@csnet-relay
  3971.         UUCP:  seismo!rpics!weltyrp
  3972. (Mail) End of article 4946 (of 4956)--what next? [npq] 
  3973.  
  3974. Article 4947 (9 more) in net.lang.c:
  3975. From: eppstein@columbia.UUCP (David Eppstein)
  3976. Subject: Re: Re: c programming style - READ THIS
  3977. Message-ID: <1020@columbia.UUCP>
  3978. Date: 31 Aug 85 18:38:03 GMT
  3979. Date-Received: 2 Sep 85 08:19:10 GMT
  3980. References: <90@rtp47.UUCP> <5400011@prism.UUCP>
  3981. Reply-To: eppstein@columbia.UUCP (David Eppstein)
  3982. Organization: Columbia University
  3983. Lines: 25
  3984.  
  3985. --MORE--(31%)
  3986. In article <5400011@prism.UUCP> mer@prism.UUCP writes:
  3987. > Since 'p+n', where p is a pointer and n is an integer, is equivalent to
  3988. > adding n*sizeof(whatever p points to), the safe and portable way of adding
  3989. > an integer to a pointer treated as an integer is 
  3990. >        (char *)p + n
  3991. > since (I think) character are always a byte wide.  If that's not always the
  3992. > case, I apologize; on the other hand, it's probably safe than converting
  3993. > a pointer to an int or a long;  I had trouble porting something from a VAX
  3994. > to a Pyramid because of a cast of this sort.
  3995.  
  3996. Not the case.  For instance on the DEC-20, adding integers to (int *)
  3997. looks like adding integers to integers but adding them to (char *)
  3998. does something totally different (divides by number of bytes per word,
  3999. adds word quotient as an integer, adds number of bytes remainder
  4000. multiplied by byte size shifted over by 30 bits; bytes per word and
  4001. bits per byte have to be calculated from the pointer itself because
  4002. we have both 7-bit bytes packed 5 to a word and 9-bit bytes packed
  4003. 4 to a word (others too but those are the ones used in C); this is not
  4004. as bad as it sounds because there is a machine instruction to do it all).
  4005.  
  4006. On all implementations that I know about, coercing the pointer to (long) and
  4007. adding your integer will work.  However this is still somewhat nonportable
  4008. and you are better off doing whatever you are trying to do some other,
  4009. clean, portable way not involving adding integers as integers to pointers.
  4010. (Mail) End of article 4947 (of 4956)--what next? [npq] 
  4011.  
  4012. Article 4948 (8 more) in net.lang.c:
  4013. From: rcd@opus.UUCP (Dick Dunn)
  4014. Subject: Re: Cryptic C (enum as boolean type)
  4015. Message-ID: <19@opus.UUCP>
  4016. Date: 30 Aug 85 05:02:04 GMT
  4017. Date-Received: 2 Sep 85 08:30:59 GMT
  4018. References: <2913@ncsu.UUCP> <709@brl-tgr.ARPA> <1056@mtgzz.UUCP>
  4019. Organization: NBI,Inc, Boulder CO
  4020. Lines: 16
  4021.  
  4022. --MORE--(45%)
  4023. > Instead of using #defines for the boolean values, I
  4024. > would rather see enumerated data types used.  In general,
  4025. > C programmers seem to prefer #defines to defining a data
  4026. > type that can be checked during compilation.
  4027. >       typedef enum { False , True } Boolean;
  4028.  
  4029. Whether this works depends on your compiler's view of enums.  If it treats
  4030. enums as a slight variant on integers (which to my tastes is pretty
  4031. sloppy), you're OK.  However, if it uses the very restricted view which
  4032. doesn't allow arithmetic on enums, the above definition will prevent the
  4033. "usual" logical operators !, &, ^, and | from working with objects of type
  4034. Boolean.
  4035. -- 
  4036. Dick Dunn       {hao,ucbvax,allegra}!nbires!rcd         (303)444-5710 x3086
  4037.    ...Relax...don't worry...have a homebrew.
  4038. (Mail) End of article 4948 (of 4956)--what next? [npq] 
  4039.  
  4040. Article 4949 (7 more) in net.lang.c:
  4041. From: lee@eel.UUCP
  4042. Subject: Re: Re: how has C bitten you?  (Really,
  4043. Message-ID: <2000001@eel.UUCP>
  4044. Date: 29 Aug 85 02:52:00 GMT
  4045. Date-Received: 3 Sep 85 04:00:53 GMT
  4046. References: <259@watmum.UUCP>
  4047. Lines: 24
  4048.  
  4049. --MORE--(31%)
  4050.  
  4051. >>Gee....and I thought a zero pointer was guaranteed not to point to
  4052. >>anything valid (K&R says this).
  4053.  
  4054. >All valid implementations of C guarantee this.  Obviously, the
  4055. >implementation of C that this was done on is not valid.  He should complain
  4056. >to the vendor.  (Yes, there have been such implementations; one well-known
  4057. >chip maker's first UNIX release didn't put the necessary shim at data
  4058. >location 0 on a separate I&D space program.  They fixed it shortly
  4059. >afterwards.)
  4060.  
  4061. Speaking of issues that have been beaten to death!  K&R says only that the
  4062. value 0 is distinguishable from pointers that point to objects, and that
  4063. therefore the value zero is not a "valid" pointer.  It certainly does not
  4064. say that the 0 pointer will give you the "null" or empty value of any
  4065. object, and in particular it does not promise that there will be an integer
  4066. zero if you dereference (int*)0, or a character zero if you dereference
  4067. (char*)0, nor a memory fault if you reference (foo*)0.
  4068.  
  4069. NO, you cannot depend upon the value obtained by dereferencing ANY pointer
  4070. that has been assigned the value zero.  It does not point to any object;
  4071. the implementation of C does not guarantee  to protect you from erroneously
  4072. trying to access that object and the result is unpredictable over various
  4073. implementations.
  4074. (Mail) End of article 4949 (of 4956)--what next? [npq] 
  4075.  
  4076. Article 4950 (6 more) in net.lang.c:
  4077. From: darryl@ISM780.UUCP
  4078. Subject: Re: Re: how has C bitten you?  (Really,
  4079. Message-ID: <30000009@ISM780.UUCP>
  4080. Date: 29 Aug 85 13:48:00 GMT
  4081. Date-Received: 3 Sep 85 04:01:11 GMT
  4082. References: <259@watmum.UUCP>
  4083. Lines: 19
  4084.  
  4085. --MORE--(40%)
  4086.  
  4087. []
  4088.  
  4089. One final, subtle, point.  K&R does not guarantee that the *value* 0 is
  4090. distinguishable from all other pointers, but rather, that the *constant* 0
  4091. is.  That is to say, you may compare against 0 to determine the validity of
  4092. a pointer (or assign to guarantee invalidity), but you may not assume that
  4093. comparison against (or assignment of) an int variable whose value is 0 will
  4094. have the same result.  This picky distinction probably doesn't affect any
  4095. of the better known chips, but might be important on a machine where a null
  4096. pointer is not a bit string of 0s.
  4097.  
  4098.             --Darryl Richman, INTERACTIVE Systems Corp.
  4099.             ...!cca!ima!ism780!darryl
  4100.             The views expressed above are my opinions only.
  4101.  
  4102. P.S.:  I know that this sounds amazing, so look at the top of K&R p190,
  4103. under the section 7.7, equality operators (second paragraph), and again
  4104. on top of p192, section 7.14, assignment operators.
  4105. (Mail) End of article 4950 (of 4956)--what next? [npq] 
  4106.  
  4107. Article 4951 (5 more) in net.lang.c:
  4108. From: richw@ada-uts.UUCP
  4109. Subject: "handy.h"
  4110. Message-ID: <10200006@ada-uts.UUCP>
  4111. Date: 28 Aug 85 14:39:00 GMT
  4112. Date-Received: 3 Sep 85 04:01:19 GMT
  4113. Lines: 16
  4114.  
  4115. --MORE--(52%)
  4116.  
  4117. I'm interested in coming up with an include file, say "handy.h",
  4118. which declares a lot of commonly useful "stuff".  A lot of discussion
  4119. (an AWFUL lot) has been going on about Boolean typedefs/defines --
  4120. that's the sort of thing I'm looking for:
  4121.  
  4122.     typedef enum { false, true } bool;
  4123.  
  4124. Other plausible candidates for this "second stdio.h" might be:
  4125.  
  4126.     typedef char *string;
  4127.     #define FORMFEED '\014'      /*  ASCII form feed  */
  4128.  
  4129. Any other suggestions would be appreciated.
  4130.  
  4131. -- Rich Wagner
  4132. (Mail) End of article 4951 (of 4956)--what next? [npq] 
  4133.  
  4134.  
  4135. Article 4954 (2 more) in net.lang.c:
  4136. From: peter@graffiti.UUCP (Peter da Silva)
  4137. Subject: Re: \"handy.h\"
  4138. Message-ID: <148@graffiti.UUCP>
  4139. Date: 31 Aug 85 14:40:13 GMT
  4140. Date-Received: 3 Sep 85 05:21:58 GMT
  4141. References: <1133@brl-tgr.ARPA>
  4142. Organization: The Power Elite, Houston, TX
  4143. Lines: 8
  4144.  
  4145. --MORE--(78%)
  4146. > #define               FALSE           0
  4147. > #define               TRUE            1
  4148. > #define               EOL             '\0'            /* End-of-line */
  4149.  
  4150. #define EOL '\n'
  4151. #define EOS '\0'
  4152.  
  4153. ... unless, of course, you're on a really weird O/S.
  4154. (Mail) End of article 4954 (of 4956)--what next? [npq] 
  4155.  
  4156. Article 4955 (1 more) in net.lang.c:
  4157. From: doug@terak.UUCP (Doug Pardee)
  4158. Subject: Numeric comparisons
  4159. Message-ID: <693@terak.UUCP>
  4160. Date: 30 Aug 85 18:29:16 GMT
  4161. Date-Received: 3 Sep 85 06:13:03 GMT
  4162. References: <10176@ucbvax.ARPA> <5118@mit-eddie.UUCP>
  4163. Organization: Calcomp Display Products Division, Scottsdale, AZ, USA
  4164. Lines: 24
  4165.  
  4166. --MORE--(41%)
  4167. > ... since comparison is merely done by subtraction (a
  4168. > compare instruction is usually just a subtract instruction that doesn't
  4169. > store the result anywhere)...
  4170.  
  4171. Compiler writers note -- a comparison is not "just a subtract".
  4172. For example:
  4173.  
  4174. #define NBITS 16
  4175. /* NBITS is number of bits in an integer */
  4176.    int a, b;
  4177.    a = 3 << (NBITS-3);  /* 24576 for NBITS=16 */
  4178.    b = -a;
  4179.    if (a>b)
  4180.       printf("Comparison was done by bit-wise comparison\n");
  4181.    else
  4182.       printf("Comparison was done by subtraction\n");   /* WRONG */
  4183.  
  4184. Compiler users note -- if your compiler gives the wrong results, the
  4185. compiler writer might not be completely at fault.  Many early CPU
  4186. chips (8080A, Z80, 6502, etc.) did comparison by subtraction, and a
  4187. compiler would have had to generate extra code to test for Overflow
  4188. in order to get the correct result.
  4189. -- 
  4190. Doug Pardee -- CalComp -- {seismo!noao,decvax!noao,ihnp4}!terak!doug
  4191. (Mail) End of article 4955 (of 4956)--what next? [npq] 
  4192.  
  4193. Article 4956 in net.lang.c:
  4194. From: ark@alice.UucP (Andrew Koenig)
  4195. Subject: Re: Re: how has C bitten you?  (Really,
  4196. Message-ID: <4244@alice.UUCP>
  4197. Date: 30 Aug 85 16:04:11 GMT
  4198. Date-Received: 4 Sep 85 05:53:32 GMT
  4199. References: <2000001@eel.UUCP>
  4200. Organization: Bell Labs, Murray Hill
  4201. Lines: 27
  4202.  
  4203. --MORE--(25%)
  4204. >>All valid implementations of C guarantee this.  Obviously, the
  4205. >>implementation of C that this was done on is not valid.  He should complain
  4206. >>to the vendor.  (Yes, there have been such implementations; one well-known
  4207. >>chip maker's first UNIX release didn't put the necessary shim at data
  4208. >>location 0 on a separate I&D space program.  They fixed it shortly
  4209. >>afterwards.)
  4210.  
  4211. >Speaking of issues that have been beaten to death!  K&R says only that the
  4212. >value 0 is distinguishable from pointers that point to objects, and that
  4213. >therefore the value zero is not a "valid" pointer.  It certainly does not
  4214. >say that the 0 pointer will give you the "null" or empty value of any
  4215. >object, and in particular it does not promise that there will be an integer
  4216. >zero if you dereference (int*)0, or a character zero if you dereference
  4217. >(char*)0, nor a memory fault if you reference (foo*)0.
  4218.  
  4219. >NO, you cannot depend upon the value obtained by dereferencing ANY pointer
  4220. >that has been assigned the value zero.  It does not point to any object;
  4221. >the implementation of C does not guarantee  to protect you from erroneously
  4222. >trying to access that object and the result is unpredictable over various
  4223. >implementations.
  4224.  
  4225. I think the "necessary shim" referred to in the first note quoted
  4226. above has nothing to do with a value intended to ensure that *(int*)0
  4227. give a defined value.  Rather, it is a dummy variable located at
  4228. location 0 designed to ensure the NOTHING ELSE find itself at location
  4229. 0 by accident!  The trouble with putting a variable at location 0
  4230. is that its address will then erroneously appear to be NULL.
  4231. (Mail) End of article 4956 (of 4956)--what next? [npq] 
  4232.  
  4233. End of newsgroup net.lang.c.
  4234.  
  4235.